Welcome to mirror list, hosted at ThFree Co, Russian Federation.

creator_crashpad_apple.cpp « creator « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2314b4aa6bb94133a50d284afbf88e0df6160bc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * ***** END GPL LICENSE BLOCK *****
 */

/** \file creator/creator_crashpad.cpp
 *  \ingroup creator
 */

#include <map>
#include <string>
#include <vector>

#include "client/crashpad_client.h"
#include "client/settings.h"
#include "base/files/file_path.h"
#include "client/crash_report_database.h"
extern "C"
{
#include "BLI_path_util.h"
#include "BLI_utildefines.h"
#include "BKE_appdir.h"
#include "BKE_blender_version.h"
#include "creator_intern.h"
}

using namespace std;

using namespace crashpad;

static CrashpadClient client;
static bool startCrashHandler()
{
	  bool rc;
	  std::map<std::string, std::string> annotations;
	  std::vector<std::string> arguments;
	  char handler_path_cstr[PATH_MAX] = { 0 };
	  char blender_version[PATH_MAX] = { 0 };

	  std::string db_path = BKE_appdir_folder_id_create(BLENDER_USER_DATAFILES, "crashpad");

	  BLI_path_append(handler_path_cstr, sizeof(handler_path_cstr), BKE_appdir_program_dir());
	  BLI_path_append(handler_path_cstr, sizeof(handler_path_cstr), "../Resources/crashpad/crashpad_handler");
			   
	  std::string handler_path(handler_path_cstr);

	  printf("handler: %s\n", handler_path_cstr);
	  
	  std::string url(CRASHPAD_URL);
	  
	  arguments.push_back("--no-upload-gzip");
	  arguments.push_back("--no-rate-limit");

	  sprintf(blender_version, BLEND_VERSION_STRING_FMT);
	  annotations["build_version"] = blender_version;
#ifdef BUILD_DATE
	  annotations["build_version_char"] = STRINGIFY(BLENDER_VERSION_CHAR);
	  annotations["build_cycle"] = STRINGIFY(BLENDER_VERSION_CYCLE);
	  annotations["build_date"] = build_date;
	  annotations["build_time"] = build_time;
	  annotations["build_hash"] = build_hash;
	  annotations["build_commit_date"] = build_commit_date;
	  annotations["build_commit_time"] = build_commit_time;
	  annotations["build_branch"] = build_branch;
	  annotations["build_platform"] = build_platform;
	  annotations["build_type"] = build_type;
	  annotations["build_cflags"] = build_cflags;
	  annotations["build_cxxflags"] = build_cxxflags;
	  annotations["build_linkflags"] = build_linkflags;
	  annotations["build_system"] = build_system;
#endif

	  base::FilePath db(db_path);
	  base::FilePath handler(handler_path);

	  std::unique_ptr<CrashReportDatabase> database =
		  crashpad::CrashReportDatabase::Initialize(db);
	  if (database == nullptr || database->GetSettings() == NULL)
		  return false;

	  /* Enable automated uploads. however the handler will only be called when */
	  /* the user consents to it, this way no crashdumps will be made if they */ 
	  /* decline, and we can still have some custom UI */
	  database->GetSettings()->SetUploadsEnabled(true);

	  rc = client.StartHandler(handler,
		  db,
		  db,
		  url,
		  annotations,
		  arguments,
		  true,
		  true);
	  if (rc == false)
		  return false;

	  return true;
  }


extern "C" 
{
	void crashpad_init()
	{
		startCrashHandler();
	}
}