Skip to content

Commit 50e5d13

Browse files
authored
Merge branch 'backtrace' into cmake-ninja
2 parents 82249c4 + fdd718a commit 50e5d13

File tree

15 files changed

+21664
-17
lines changed

15 files changed

+21664
-17
lines changed

.github/workflows/main.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,25 @@ jobs:
203203
with:
204204
submodules: recursive
205205

206+
- name: Set env armeabi-v7a
207+
if: ${{ matrix.abi == 'armeabi-v7a' }}
208+
run: echo "SSL_MODE=NONE" >> $GITHUB_ENV
209+
210+
- name: Set env others
211+
if: ${{ matrix.abi != 'armeabi-v7a' }}
212+
run: echo "SSL_MODE=OPENSSL" >> $GITHUB_ENV
213+
206214
- name: Install NDK (optional)
207215
# available on GitHub Actions host (as of 7/24/22) listed below
208216
if: ${{ matrix.ndk }} != '21.4.7075529' && ${{ matrix.ndk }} != '23.2.8568313' && ${{ matrix.ndk }} != '24.0.8215888'
209217
run: |
210218
echo "y" | sudo $ANDROID_HOME/tools/bin/sdkmanager --install "ndk;${{ matrix.ndk }}" --sdk_root=${ANDROID_SDK_ROOT} >/dev/null 2>&1
211219
#ls -lsa $ANDROID_HOME/ndk/${{ matrix.ndk }}/platforms
212220
213-
214221
- name: CMake
215222
run: |
216223
mkdir cbuild
217-
cmake -S . -B cbuild/ -DCMAKE_TOOLCHAIN_FILE=$ANDROID_HOME/ndk/${{ matrix.ndk }}/build/cmake/android.toolchain.cmake -DANDROID_ABI=${{ matrix.abi }} -DANDROID_PLATFORM=android-${{ matrix.apiLevel }} -DANDROID_NATIVE_API_LEVEL=${{ matrix.apiLevel }} -DANDROID_TOOLCHAIN=clang -DBUILD_EXAMPLES=TRUE -G Ninja
224+
cmake -S . -B cbuild/ -DCMAKE_TOOLCHAIN_FILE=$ANDROID_HOME/ndk/${{ matrix.ndk }}/build/cmake/android.toolchain.cmake -DANDROID_ABI=${{ matrix.abi }} -DANDROID_PLATFORM=android-${{ matrix.apiLevel }} -DANDROID_NATIVE_API_LEVEL=${{ matrix.apiLevel }} -DANDROID_TOOLCHAIN=clang -DANDROID_SSL_MODE=${{ env.SSL_MODE }} -DBUILD_EXAMPLES=TRUE -G Ninja
218225
cmake --build cbuild/
219226
220227
- name: Crashpad distribution ZIP

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
cmake_minimum_required(VERSION 3.12)
22
project(backtrace_crashpad LANGUAGES C CXX)
3+
cmake_policy(SET CMP0077 NEW)
34

45
if (UNIX AND NOT APPLE)
56
set(LINUX TRUE)
@@ -42,7 +43,10 @@ target_compile_definitions(backtrace_common INTERFACE
4243
CRASHPAD_LSS_SOURCE_EMBEDDED)
4344

4445
if (ANDROID)
45-
add_subdirectory(third_party/openssl-android-binary)
46+
option(ANDROID_SSL_MODE "Android SSL mode" "OPENSSL")
47+
if (ANDROID_SSL_MODE STREQUAL "OPENSSL")
48+
add_subdirectory(third_party/openssl-android-binary)
49+
endif()
4650
elseif (APPLE)
4751
# do nothing
4852
elseif (LINUX)

client/crash_report_database.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ class CrashReportDatabase {
176176
return attachment_map_;
177177
}
178178

179+
#if BUILDFLAG(IS_ANDROID)
180+
//! \brief Returns the database that this report belongs to.
181+
CrashReportDatabase* GetDatabase() const { return database_; }
182+
#endif
183+
179184
private:
180185
friend class CrashReportDatabase;
181186
friend class CrashReportDatabaseGeneric;

client/crashpad_client.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ class CrashpadClient {
162162
static int ConsecutiveCrashesCount(const base::FilePath& database);
163163
#endif
164164

165+
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || DOXYGEN
166+
//! \brief Enable the use of a GUID override.
167+
//!
168+
//! This function must be called prior to `StartHandler()`
169+
//!
170+
//! \param[in] uuid The GUID to use as the GUID.
171+
//!
172+
//! \return `true` on success. Otherwise `false` with a message logged.
173+
bool OverrideGuid(const std::string& uuid);
174+
bool OverrideGuid(const UUID& uuid);
175+
#endif // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || DOXYGEN
176+
165177
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || \
166178
DOXYGEN
167179
//! \brief Retrieve the socket and process ID for the handler.
@@ -845,6 +857,10 @@ class CrashpadClient {
845857
UUID run_uuid_;
846858
std::set<int> unhandled_signals_;
847859
#endif // BUILDFLAG(IS_APPLE)
860+
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID)
861+
bool uuid_override_enabled_ = false;
862+
UUID uuid_override_;
863+
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID)
848864
};
849865

850866
} // namespace crashpad

client/crashpad_client_linux.cc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
#include "util/posix/signals.h"
5151
#include "util/posix/spawn_subprocess.h"
5252

53+
#if defined(CRASHPAD_USE_BORINGSSL) && BUILDFLAG(IS_ANDROID)
54+
#include "util/backtrace/android_cert_store.h"
55+
#endif
56+
5357
namespace crashpad {
5458

5559
namespace {
@@ -449,6 +453,10 @@ bool CrashpadClient::StartHandler(
449453
const std::vector<base::FilePath>& attachments) {
450454
DCHECK(!asynchronous_start);
451455

456+
#if defined(CRASHPAD_USE_BORINGSSL) && BUILDFLAG(IS_ANDROID)
457+
backtrace::android_cert_store::create(database);
458+
#endif
459+
452460
ScopedFileHandle client_sock, handler_sock;
453461
if (!UnixCredentialSocket::CreateCredentialSocketpair(&client_sock,
454462
&handler_sock)) {
@@ -467,6 +475,11 @@ bool CrashpadClient::StartHandler(
467475
argv.push_back("--annotation=run-uuid=" + run_uuid_.ToString());
468476
}
469477

478+
if (uuid_override_enabled_) {
479+
argv.push_back("--annotation=_backtrace_internal_guid_override=" +
480+
uuid_override_.ToString());
481+
}
482+
470483
if (!SpawnSubprocess(argv, nullptr, handler_sock.get(), false, nullptr)) {
471484
return false;
472485
}
@@ -501,6 +514,21 @@ int CrashpadClient::ConsecutiveCrashesCount(const base::FilePath& database)
501514
}
502515
#endif
503516

517+
bool CrashpadClient::OverrideGuid(const std::string& uuid)
518+
{
519+
UUID new_uuid;
520+
if (!new_uuid.InitializeFromString(uuid))
521+
return false;
522+
return OverrideGuid(new_uuid);
523+
}
524+
525+
bool CrashpadClient::OverrideGuid(const UUID& uuid)
526+
{
527+
uuid_override_enabled_ = true;
528+
uuid_override_ = uuid;
529+
return true;
530+
}
531+
504532
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
505533
// static
506534
bool CrashpadClient::GetHandlerSocket(int* sock, pid_t* pid) {
@@ -707,13 +735,22 @@ bool CrashpadClient::StartHandlerAtCrash(
707735
std::vector<std::string> argv = BuildHandlerArgvStrings(
708736
handler, database, metrics_dir, url, annotations, arguments, attachments);
709737

738+
#if defined(CRASHPAD_USE_BORINGSSL) && BUILDFLAG(IS_ANDROID)
739+
backtrace::android_cert_store::create(database);
740+
#endif
741+
710742
if (crash_loop_detection_) {
711743
namespace clc = backtrace::crash_loop_detection;
712744
bool ok = clc::CrashLoopDetectionAppend(database, run_uuid_);
713745
DCHECK(ok);
714746
argv.push_back("--annotation=run-uuid=" + run_uuid_.ToString());
715747
}
716748

749+
if (uuid_override_enabled_) {
750+
argv.push_back("--annotation=_backtrace_internal_guid_override=" +
751+
uuid_override_.ToString());
752+
}
753+
717754
auto signal_handler = LaunchAtCrashHandler::Get();
718755
return signal_handler->Initialize(&argv, nullptr, &unhandled_signals_);
719756
}

examples/linux/demo/demo.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ startCrashHandler(std::string const& url, std::string const& handler_path,
2121

2222
std::map<std::string, std::string> annotations;
2323
std::vector<std::string> arguments;
24-
bool rc;
2524

2625
/*
2726
* THE FOLLOWING ANNOTATIONS MUST BE SET.
@@ -53,7 +52,11 @@ startCrashHandler(std::string const& url, std::string const& handler_path,
5352
/* Enable automated uploads. */
5453
database->GetSettings()->SetUploadsEnabled(true);
5554

56-
return CrashpadClient{}.StartHandler(
55+
CrashpadClient client{};
56+
57+
client.OverrideGuid("11111111-2222-3333-4444-555555555555");
58+
59+
return client.StartHandler(
5760
handler, db, db, url, annotations, arguments, false, false, {}
5861
);
5962
}

handler/crash_report_upload_thread.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,13 @@ CrashReportUploadThread::UploadResult CrashReportUploadThread::UploadReport(
341341
// TODO(mark): The timeout should be configurable by the client.
342342
http_transport->SetTimeout(internal::kUploadReportTimeoutSeconds);
343343

344+
#if defined(CRASHPAD_USE_BORINGSSL)
345+
#if BUILDFLAG(IS_ANDROID)
346+
http_transport->SetRootCACertificatePath(
347+
report->GetDatabase()->DatabasePath());
348+
#endif // BUILDFLAG(IS_ANDROID)
349+
#endif // defined(CRASHPAD_USE_BORINGSSL)
350+
344351
std::string url = url_;
345352
if (options_.identify_client_via_url) {
346353
// Add parameters to the URL which identify the client to the server.

handler/minidump_to_upload_parameters.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,16 @@ std::map<std::string, std::string> BreakpadHTTPFormParametersFromMinidump(
7777
InsertOrReplaceMapEntry(&parameters, "list_annotations", list_annotations);
7878
}
7979

80-
UUID client_id;
81-
process_snapshot->ClientID(&client_id);
82-
InsertOrReplaceMapEntry(&parameters, "guid", client_id.ToString());
80+
if (parameters.count("_backtrace_internal_guid_override")) {
81+
InsertOrReplaceMapEntry(&parameters,
82+
"guid",
83+
parameters.at("_backtrace_internal_guid_override"));
84+
parameters.erase("_backtrace_internal_guid_override");
85+
} else {
86+
UUID client_id;
87+
process_snapshot->ClientID(&client_id);
88+
InsertOrReplaceMapEntry(&parameters, "guid", client_id.ToString());
89+
}
8390

8491
return parameters;
8592
}

util/CMakeLists.txt

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ if (LINUX)
230230
./misc/capture_context_linux.S
231231
./misc/paths_linux.cc
232232
./misc/time_linux.cc
233-
./net/http_transport_libcurl.cc
234233
./net/http_transport_socket.cc
235234
./posix/process_info_linux.cc
236235
./posix/scoped_mmap.cc
@@ -310,6 +309,13 @@ if (WIN32)
310309
endif ()
311310
endif (WIN32)
312311

312+
if (ANDROID)
313+
list(APPEND CRASHPAD_UTIL_LIBRARY_FILES
314+
./backtrace/android_cert_store.cc
315+
./backtrace/android_cert_store.h
316+
./backtrace/certs_pem.h
317+
)
318+
endif (ANDROID)
313319

314320
add_library(util OBJECT ${CRASHPAD_UTIL_LIBRARY_FILES})
315321
target_compile_features(util PUBLIC cxx_std_17)
@@ -362,7 +368,10 @@ if (APPLE)
362368
endif (APPLE)
363369

364370
if (ANDROID)
365-
target_link_libraries(util PUBLIC openssl-android-binary)
371+
if (ANDROID_SSL_MODE STREQUAL "OPENSSL")
372+
target_link_libraries(util PUBLIC openssl-android-binary)
373+
elseif(ANDROID_SSL_MODE STREQUAL "NONE")
374+
endif ()
366375
endif (ANDROID)
367376

368377
if (UNIX)
@@ -377,16 +386,22 @@ target_include_directories(util PUBLIC ..)
377386
target_link_libraries(util PUBLIC mini_chromium ZLIB::ZLIB backtrace_common)
378387

379388
if (LINUX AND NOT ANDROID)
380-
if (CURL_FOUND)
381-
target_link_libraries(util PUBLIC curl)
382-
endif (CURL_FOUND)
383-
384389
if (OPENSSL_FOUND)
385390
target_compile_definitions(util PUBLIC CRASHPAD_USE_BORINGSSL)
386391
target_link_libraries(util PUBLIC OpenSSL::SSL OpenSSL::Crypto)
387392
endif (OPENSSL_FOUND)
388393
endif (LINUX AND NOT ANDROID)
389394

395+
if (ANDROID)
396+
if (ANDROID_SSL_MODE STREQUAL "OPENSSL")
397+
target_link_libraries(util PUBLIC openssl-android-binary)
398+
target_compile_definitions(util PUBLIC CRASHPAD_USE_BORINGSSL)
399+
elseif(ANDROID_SSL_MODE STREQUAL "NONE")
400+
else()
401+
message(FATAL_ERROR "Unknown value for ANDROID_SSL_MODE: ${ANDROID_SSL_MODE}")
402+
endif ()
403+
endif (ANDROID)
404+
390405
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
391406
target_compile_options(util PUBLIC -Wno-multichar)
392407
endif ()

0 commit comments

Comments
 (0)