1
// Copyright (c) 2007, Google Inc.
2
// All rights reserved.
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are
8
// * Redistributions of source code must retain the above copyright
9
// notice, this list of conditions and the following disclaimer.
10
// * Redistributions in binary form must reproduce the above
11
// copyright notice, this list of conditions and the following disclaimer
12
// in the documentation and/or other materials provided with the
14
// * Neither the name of Google Inc. nor the names of its
15
// contributors may be used to endorse or promote products derived from
16
// this software without specific prior written permission.
18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
// Author: Alfred Peng
33
#include <sys/frame.h>
35
#include <sys/types.h>
36
#include <sys/utsname.h>
43
#include "client/solaris/handler/minidump_generator.h"
44
#include "client/minidump_file_writer-inl.h"
45
#include "common/solaris/file_id.h"
49
using namespace google_breakpad;
51
// Argument for the writer function.
52
struct WriterArgument {
53
MinidumpFileWriter *minidump_writer;
55
// Pid of the lwp who called WriteMinidumpToFile
58
// The stack bottom of the lwp which caused the dump.
59
// Mainly used to find the lwp id of the crashed lwp since signal
60
// handler may not be called in the lwp who caused it.
61
uintptr_t crashed_stack_bottom;
63
// Id of the crashing lwp.
66
// Signal number when crash happened. Can be 0 if this is a requested dump.
69
// The ebp of the signal handler frame on x86. Can be 0 if this is a
71
uintptr_t sighandler_ebp;
73
// User context when crash happens. Can be NULL if this is a requested dump.
74
// This is actually an out parameter, but it will be filled in at the start
78
// Used to get information about the lwps.
79
SolarisLwp *lwp_lister;
82
// Holding context information for the callback of finding the crashing lwp.
83
struct FindCrashLwpContext {
84
const SolarisLwp *lwp_lister;
85
uintptr_t crashing_stack_bottom;
88
FindCrashLwpContext() :
90
crashing_stack_bottom(0UL),
95
// Callback for list lwps.
96
// It will compare the stack bottom of the provided lwp with the stack
97
// bottom of the crashed lwp, it they are eqaul, this lwp is the one
99
bool IsLwpCrashedCallback(lwpstatus_t *lsp, void *context) {
100
FindCrashLwpContext *crashing_context =
101
static_cast<FindCrashLwpContext *>(context);
102
const SolarisLwp *lwp_lister = crashing_context->lwp_lister;
103
const prgregset_t *gregs = &(lsp->pr_reg);
105
uintptr_t last_ebp = (*gregs)[R_FP];
107
uintptr_t last_ebp = (*gregs)[EBP];
109
uintptr_t stack_bottom = lwp_lister->GetLwpStackBottom(last_ebp);
110
if (stack_bottom > last_ebp &&
111
stack_bottom == crashing_context->crashing_stack_bottom) {
112
// Got it. Stop iteration.
113
crashing_context->crashing_lwpid = lsp->pr_lwpid;
120
// Find the crashing lwpid.
121
// This is done based on stack bottom comparing.
122
int FindCrashingLwp(uintptr_t crashing_stack_bottom,
124
const SolarisLwp *lwp_lister) {
125
FindCrashLwpContext context;
126
context.lwp_lister = lwp_lister;
127
context.crashing_stack_bottom = crashing_stack_bottom;
128
CallbackParam<LwpCallback> callback_param(IsLwpCrashedCallback,
130
lwp_lister->Lwp_iter_all(lwp_lister->getpid(), &callback_param);
131
return context.crashing_lwpid;
134
bool WriteLwpStack(const SolarisLwp *lwp_lister,
136
UntypedMDRVA *memory,
137
MDMemoryDescriptor *loc) {
138
uintptr_t stack_bottom = lwp_lister->GetLwpStackBottom(last_esp);
139
if (stack_bottom >= last_esp) {
140
int size = stack_bottom - last_esp;
142
if (!memory->Allocate(size))
144
memory->Copy(reinterpret_cast<void *>(last_esp), size);
145
loc->start_of_memory_range = last_esp;
146
loc->memory = memory->location();
154
bool WriteContext(MDRawContextSPARC *context, ucontext_t *sig_ctx) {
155
assert(sig_ctx != NULL);
156
int* regs = sig_ctx->uc_mcontext.gregs;
157
context->context_flags = MD_CONTEXT_SPARC_FULL;
159
context->ccr = (unsigned int)(regs[0]);
160
context->pc = (unsigned int)(regs[REG_PC]);
161
context->npc = (unsigned int)(regs[REG_nPC]);
162
context->y = (unsigned int)(regs[REG_Y]);
163
context->asi = (unsigned int)(regs[19]);
164
context->fprs = (unsigned int)(regs[20]);
166
for ( int i = 0 ; i < 32; ++i ) {
170
for ( int i = 1 ; i < 16; ++i ) {
171
context->g_r[i] = (uintptr_t)(sig_ctx->uc_mcontext.gregs[i + 3]);
173
context->g_r[30] = (uintptr_t)(((struct frame *)context->g_r[14])->fr_savfp);
178
bool WriteContext(MDRawContextSPARC *context, prgregset_t regs,
179
prfpregset_t *fp_regs) {
180
if (!context || !regs)
183
context->context_flags = MD_CONTEXT_SPARC_FULL;
185
context->ccr = (uintptr_t)(regs[32]);
186
context->pc = (uintptr_t)(regs[R_PC]);
187
context->npc = (uintptr_t)(regs[R_nPC]);
188
context->y = (uintptr_t)(regs[R_Y]);
189
context->asi = (uintptr_t)(regs[36]);
190
context->fprs = (uintptr_t)(regs[37]);
191
for ( int i = 0 ; i < 32 ; ++i ){
192
context->g_r[i] = (uintptr_t)(regs[i]);
198
bool WriteContext(MDRawContextX86 *context, prgregset_t regs,
199
prfpregset_t *fp_regs) {
200
if (!context || !regs)
203
context->context_flags = MD_CONTEXT_X86_FULL;
205
context->cs = regs[CS];
206
context->ds = regs[DS];
207
context->es = regs[ES];
208
context->fs = regs[FS];
209
context->gs = regs[GS];
210
context->ss = regs[SS];
211
context->edi = regs[EDI];
212
context->esi = regs[ESI];
213
context->ebx = regs[EBX];
214
context->edx = regs[EDX];
215
context->ecx = regs[ECX];
216
context->eax = regs[EAX];
217
context->ebp = regs[EBP];
218
context->eip = regs[EIP];
219
context->esp = regs[UESP];
220
context->eflags = regs[EFL];
224
#endif /* TARGET_CPU_XXX */
226
// Write information about a crashed Lwp.
227
// When a lwp crash, kernel will write something on the stack for processing
228
// signal. This makes the current stack not reliable, and our stack walker
229
// won't figure out the whole call stack for this. So we write the stack at the
230
// time of the crash into the minidump file, not the current stack.
231
bool WriteCrashedLwpStream(MinidumpFileWriter *minidump_writer,
232
const WriterArgument *writer_args,
233
const lwpstatus_t *lsp,
235
assert(writer_args->sig_ctx != NULL);
237
lwp->thread_id = lsp->pr_lwpid;
240
UntypedMDRVA memory(minidump_writer);
241
if (!WriteLwpStack(writer_args->lwp_lister,
242
writer_args->sig_ctx->uc_mcontext.gregs[REG_O6],
247
TypedMDRVA<MDRawContextSPARC> context(minidump_writer);
248
if (!context.Allocate())
250
lwp->thread_context = context.location();
251
memset(context.get(), 0, sizeof(MDRawContextSPARC));
252
return WriteContext(context.get(), writer_args->sig_ctx);
254
UntypedMDRVA memory(minidump_writer);
255
if (!WriteLwpStack(writer_args->lwp_lister,
256
writer_args->sig_ctx->uc_mcontext.gregs[UESP],
261
TypedMDRVA<MDRawContextX86> context(minidump_writer);
262
if (!context.Allocate())
264
lwp->thread_context = context.location();
265
memset(context.get(), 0, sizeof(MDRawContextX86));
266
return WriteContext(context.get(),
267
(int *)&writer_args->sig_ctx->uc_mcontext.gregs,
268
&writer_args->sig_ctx->uc_mcontext.fpregs);
272
bool WriteLwpStream(MinidumpFileWriter *minidump_writer,
273
const SolarisLwp *lwp_lister,
274
const lwpstatus_t *lsp, MDRawThread *lwp) {
275
prfpregset_t fp_regs = lsp->pr_fpreg;
276
const prgregset_t *gregs = &(lsp->pr_reg);
277
UntypedMDRVA memory(minidump_writer);
279
if (!WriteLwpStack(lwp_lister,
286
TypedMDRVA<MDRawContextSPARC> context(minidump_writer);
287
if (!context.Allocate())
289
// should be the thread_id
290
lwp->thread_id = lsp->pr_lwpid;
291
lwp->thread_context = context.location();
292
memset(context.get(), 0, sizeof(MDRawContextSPARC));
294
if (!WriteLwpStack(lwp_lister,
301
TypedMDRVA<MDRawContextX86> context(minidump_writer);
302
if (!context.Allocate())
304
// should be the thread_id
305
lwp->thread_id = lsp->pr_lwpid;
306
lwp->thread_context = context.location();
307
memset(context.get(), 0, sizeof(MDRawContextX86));
308
#endif /* TARGET_CPU_XXX */
309
return WriteContext(context.get(), (int *)gregs, &fp_regs);
312
bool WriteCPUInformation(MDRawSystemInfo *sys_info) {
314
char *major, *minor, *build;
316
sys_info->number_of_processors = sysconf(_SC_NPROCESSORS_CONF);
317
sys_info->processor_architecture = MD_CPU_ARCHITECTURE_UNKNOWN;
318
if (uname(&uts) != -1) {
319
// Match "i86pc" as X86 architecture.
320
if (strcmp(uts.machine, "i86pc") == 0)
321
sys_info->processor_architecture = MD_CPU_ARCHITECTURE_X86;
322
else if (strcmp(uts.machine, "sun4u") == 0)
323
sys_info->processor_architecture = MD_CPU_ARCHITECTURE_SPARC;
327
minor = strchr(major, '.');
330
sys_info->major_version = atoi(major);
331
sys_info->minor_version = atoi(minor);
333
build = strchr(uts.version, '_');
335
sys_info->build_number = atoi(build);
340
bool WriteOSInformation(MinidumpFileWriter *minidump_writer,
341
MDRawSystemInfo *sys_info) {
342
sys_info->platform_id = MD_OS_SOLARIS;
345
if (uname(&uts) != -1) {
346
char os_version[512];
347
size_t space_left = sizeof(os_version);
348
memset(os_version, 0, space_left);
349
const char *os_info_table[] = {
357
for (const char **cur_os_info = os_info_table;
358
*cur_os_info != NULL;
360
if (cur_os_info != os_info_table && space_left > 1) {
361
strcat(os_version, " ");
364
if (space_left > strlen(*cur_os_info)) {
365
strcat(os_version, *cur_os_info);
366
space_left -= strlen(*cur_os_info);
372
MDLocationDescriptor location;
373
if (!minidump_writer->WriteString(os_version, 0, &location))
375
sys_info->csd_version_rva = location.rva;
380
// Callback context for get writting lwp information.
381
struct LwpInfoCallbackCtx {
382
MinidumpFileWriter *minidump_writer;
383
const WriterArgument *writer_args;
384
TypedMDRVA<MDRawThreadList> *list;
388
bool LwpInformationCallback(lwpstatus_t *lsp, void *context) {
390
LwpInfoCallbackCtx *callback_context =
391
static_cast<LwpInfoCallbackCtx *>(context);
393
// The current lwp is the one to handle the crash. Ignore it.
394
if (lsp->pr_lwpid != pthread_self()) {
395
LwpInfoCallbackCtx *callback_context =
396
static_cast<LwpInfoCallbackCtx *>(context);
398
memset(&lwp, 0, sizeof(MDRawThread));
400
if (lsp->pr_lwpid != callback_context->writer_args->crashed_lwpid ||
401
callback_context->writer_args->sig_ctx == NULL) {
402
success = WriteLwpStream(callback_context->minidump_writer,
403
callback_context->writer_args->lwp_lister,
406
success = WriteCrashedLwpStream(callback_context->minidump_writer,
407
callback_context->writer_args,
411
callback_context->list->CopyIndexAfterObject(
412
callback_context->lwp_index++,
413
&lwp, sizeof(MDRawThread));
420
bool WriteLwpListStream(MinidumpFileWriter *minidump_writer,
421
const WriterArgument *writer_args,
422
MDRawDirectory *dir) {
423
// Get the lwp information.
424
const SolarisLwp *lwp_lister = writer_args->lwp_lister;
425
int lwp_count = lwp_lister->GetLwpCount();
428
TypedMDRVA<MDRawThreadList> list(minidump_writer);
429
if (!list.AllocateObjectAndArray(lwp_count - 1, sizeof(MDRawThread)))
431
dir->stream_type = MD_THREAD_LIST_STREAM;
432
dir->location = list.location();
433
list.get()->number_of_threads = lwp_count - 1;
435
LwpInfoCallbackCtx context;
436
context.minidump_writer = minidump_writer;
437
context.writer_args = writer_args;
438
context.list = &list;
439
context.lwp_index = 0;
440
CallbackParam<LwpCallback> callback_param(LwpInformationCallback,
443
lwp_lister->Lwp_iter_all(lwp_lister->getpid(), &callback_param);
444
return written == lwp_count;
447
bool WriteCVRecord(MinidumpFileWriter *minidump_writer,
449
const char *module_path,
451
TypedMDRVA<MDCVInfoPDB70> cv(minidump_writer);
454
const char *module_name = module_path ? module_path : "<Unknown>";
455
snprintf(path, sizeof(path), "/proc/self/object/%s", module_name);
457
size_t module_name_length = strlen(realname);
458
if (!cv.AllocateObjectAndArray(module_name_length + 1, sizeof(u_int8_t)))
460
if (!cv.CopyIndexAfterObject(0, realname, module_name_length))
463
module->cv_record = cv.location();
464
MDCVInfoPDB70 *cv_ptr = cv.get();
465
memset(cv_ptr, 0, sizeof(MDCVInfoPDB70));
466
cv_ptr->cv_signature = MD_CVINFOPDB70_SIGNATURE;
469
// Get the module identifier
470
FileID file_id(path);
471
unsigned char identifier[16];
473
if (file_id.ElfFileIdentifier(identifier)) {
474
cv_ptr->signature.data1 = (uint32_t)identifier[0] << 24 |
475
(uint32_t)identifier[1] << 16 | (uint32_t)identifier[2] << 8 |
476
(uint32_t)identifier[3];
477
cv_ptr->signature.data2 = (uint32_t)identifier[4] << 8 | identifier[5];
478
cv_ptr->signature.data3 = (uint32_t)identifier[6] << 8 | identifier[7];
479
cv_ptr->signature.data4[0] = identifier[8];
480
cv_ptr->signature.data4[1] = identifier[9];
481
cv_ptr->signature.data4[2] = identifier[10];
482
cv_ptr->signature.data4[3] = identifier[11];
483
cv_ptr->signature.data4[4] = identifier[12];
484
cv_ptr->signature.data4[5] = identifier[13];
485
cv_ptr->signature.data4[6] = identifier[14];
486
cv_ptr->signature.data4[7] = identifier[15];
491
struct ModuleInfoCallbackCtx {
492
MinidumpFileWriter *minidump_writer;
493
const WriterArgument *writer_args;
494
TypedMDRVA<MDRawModuleList> *list;
498
bool ModuleInfoCallback(const ModuleInfo &module_info, void *context) {
499
ModuleInfoCallbackCtx *callback_context =
500
static_cast<ModuleInfoCallbackCtx *>(context);
501
// Skip those modules without name, or those that are not modules.
502
if (strlen(module_info.name) == 0)
506
memset(&module, 0, sizeof(module));
507
MDLocationDescriptor loc;
513
snprintf(path, sizeof (path), "/proc/self/path/%s", module_info.name);
514
if ((count = readlink(path, buf, PATH_MAX)) < 0)
518
if ((realname = strrchr(buf, '/')) == NULL)
522
if (!callback_context->minidump_writer->WriteString(realname, 0, &loc))
525
module.base_of_image = (u_int64_t)module_info.start_addr;
526
module.size_of_image = module_info.size;
527
module.module_name_rva = loc.rva;
529
if (!WriteCVRecord(callback_context->minidump_writer, &module,
530
module_info.name, realname))
533
callback_context->list->CopyIndexAfterObject(
534
callback_context->module_index++, &module, MD_MODULE_SIZE);
538
bool WriteModuleListStream(MinidumpFileWriter *minidump_writer,
539
const WriterArgument *writer_args,
540
MDRawDirectory *dir) {
541
TypedMDRVA<MDRawModuleList> list(minidump_writer);
542
int module_count = writer_args->lwp_lister->GetModuleCount();
544
if (module_count <= 0 ||
545
!list.AllocateObjectAndArray(module_count, MD_MODULE_SIZE)) {
549
dir->stream_type = MD_MODULE_LIST_STREAM;
550
dir->location = list.location();
551
list.get()->number_of_modules = module_count;
552
ModuleInfoCallbackCtx context;
553
context.minidump_writer = minidump_writer;
554
context.writer_args = writer_args;
555
context.list = &list;
556
context.module_index = 0;
557
CallbackParam<ModuleCallback> callback(ModuleInfoCallback, &context);
558
return writer_args->lwp_lister->ListModules(&callback) == module_count;
561
bool WriteSystemInfoStream(MinidumpFileWriter *minidump_writer,
562
const WriterArgument *writer_args,
563
MDRawDirectory *dir) {
564
TypedMDRVA<MDRawSystemInfo> sys_info(minidump_writer);
566
if (!sys_info.Allocate())
569
dir->stream_type = MD_SYSTEM_INFO_STREAM;
570
dir->location = sys_info.location();
572
return WriteCPUInformation(sys_info.get()) &&
573
WriteOSInformation(minidump_writer, sys_info.get());
576
bool WriteExceptionStream(MinidumpFileWriter *minidump_writer,
577
const WriterArgument *writer_args,
578
MDRawDirectory *dir) {
579
// This happenes when this is not a crash, but a requested dump.
580
if (writer_args->sig_ctx == NULL)
583
TypedMDRVA<MDRawExceptionStream> exception(minidump_writer);
584
if (!exception.Allocate())
587
dir->stream_type = MD_EXCEPTION_STREAM;
588
dir->location = exception.location();
589
exception.get()->thread_id = writer_args->crashed_lwpid;
590
exception.get()->exception_record.exception_code = writer_args->signo;
591
exception.get()->exception_record.exception_flags = 0;
594
if (writer_args->sig_ctx != NULL) {
595
exception.get()->exception_record.exception_address =
596
writer_args->sig_ctx->uc_mcontext.gregs[REG_PC];
601
// Write context of the exception.
602
TypedMDRVA<MDRawContextSPARC> context(minidump_writer);
603
if (!context.Allocate())
605
exception.get()->thread_context = context.location();
606
memset(context.get(), 0, sizeof(MDRawContextSPARC));
607
return WriteContext(context.get(), writer_args->sig_ctx);
609
if (writer_args->sig_ctx != NULL) {
610
exception.get()->exception_record.exception_address =
611
writer_args->sig_ctx->uc_mcontext.gregs[EIP];
616
// Write context of the exception.
617
TypedMDRVA<MDRawContextX86> context(minidump_writer);
618
if (!context.Allocate())
620
exception.get()->thread_context = context.location();
621
memset(context.get(), 0, sizeof(MDRawContextX86));
622
return WriteContext(context.get(),
623
(int *)&writer_args->sig_ctx->uc_mcontext.gregs,
628
bool WriteMiscInfoStream(MinidumpFileWriter *minidump_writer,
629
const WriterArgument *writer_args,
630
MDRawDirectory *dir) {
631
TypedMDRVA<MDRawMiscInfo> info(minidump_writer);
633
if (!info.Allocate())
636
dir->stream_type = MD_MISC_INFO_STREAM;
637
dir->location = info.location();
638
info.get()->size_of_info = sizeof(MDRawMiscInfo);
639
info.get()->flags1 = MD_MISCINFO_FLAGS1_PROCESS_ID;
640
info.get()->process_id = writer_args->requester_pid;
645
bool WriteBreakpadInfoStream(MinidumpFileWriter *minidump_writer,
646
const WriterArgument *writer_args,
647
MDRawDirectory *dir) {
648
TypedMDRVA<MDRawBreakpadInfo> info(minidump_writer);
650
if (!info.Allocate())
653
dir->stream_type = MD_BREAKPAD_INFO_STREAM;
654
dir->location = info.location();
656
info.get()->validity = MD_BREAKPAD_INFO_VALID_DUMP_THREAD_ID |
657
MD_BREAKPAD_INFO_VALID_REQUESTING_THREAD_ID;
658
info.get()->dump_thread_id = getpid();
659
info.get()->requesting_thread_id = writer_args->requester_pid;
663
class AutoLwpResumer {
665
AutoLwpResumer(SolarisLwp *lwp) : lwp_(lwp) {}
666
~AutoLwpResumer() { lwp_->ControlAllLwps(false); }
671
// Prototype of writer functions.
672
typedef bool (*WriteStreamFN)(MinidumpFileWriter *,
673
const WriterArgument *,
676
// Function table to writer a full minidump.
677
const WriteStreamFN writers[] = {
679
WriteModuleListStream,
680
WriteSystemInfoStream,
681
WriteExceptionStream,
683
WriteBreakpadInfoStream,
686
// Will call each writer function in the writers table.
687
//void* MinidumpGenerator::Write(void *argument) {
688
void* Write(void *argument) {
689
WriterArgument *writer_args = static_cast<WriterArgument *>(argument);
691
if (!writer_args->lwp_lister->ControlAllLwps(true))
694
AutoLwpResumer lwpResumer(writer_args->lwp_lister);
696
if (writer_args->sighandler_ebp != 0 &&
697
writer_args->lwp_lister->FindSigContext(writer_args->sighandler_ebp,
698
&writer_args->sig_ctx)) {
699
writer_args->crashed_stack_bottom =
700
writer_args->lwp_lister->GetLwpStackBottom(
702
writer_args->sig_ctx->uc_mcontext.gregs[REG_O6]
704
writer_args->sig_ctx->uc_mcontext.gregs[UESP]
708
int crashed_lwpid = FindCrashingLwp(writer_args->crashed_stack_bottom,
709
writer_args->requester_pid,
710
writer_args->lwp_lister);
711
if (crashed_lwpid > 0)
712
writer_args->crashed_lwpid = crashed_lwpid;
715
MinidumpFileWriter *minidump_writer = writer_args->minidump_writer;
716
TypedMDRVA<MDRawHeader> header(minidump_writer);
717
TypedMDRVA<MDRawDirectory> dir(minidump_writer);
718
if (!header.Allocate())
721
int writer_count = sizeof(writers) / sizeof(writers[0]);
722
// Need directory space for all writers.
723
if (!dir.AllocateArray(writer_count))
725
header.get()->signature = MD_HEADER_SIGNATURE;
726
header.get()->version = MD_HEADER_VERSION;
727
header.get()->time_date_stamp = time(NULL);
728
header.get()->stream_count = writer_count;
729
header.get()->stream_directory_rva = dir.position();
732
MDRawDirectory local_dir;
733
for (int i = 0; i < writer_count; ++i) {
734
if ((*writers[i])(minidump_writer, writer_args, &local_dir))
735
dir.CopyIndex(dir_index++, &local_dir);
743
namespace google_breakpad {
745
MinidumpGenerator::MinidumpGenerator() {
748
MinidumpGenerator::~MinidumpGenerator() {
751
// Write minidump into file.
752
// It runs in a different thread from the crashing thread.
753
bool MinidumpGenerator::WriteMinidumpToFile(const char *file_pathname,
755
uintptr_t sighandler_ebp,
756
ucontext_t **sig_ctx) const {
757
// The exception handler thread.
758
pthread_t handler_thread;
760
assert(file_pathname != NULL);
762
if (file_pathname == NULL)
765
MinidumpFileWriter minidump_writer;
766
if (minidump_writer.Open(file_pathname)) {
767
WriterArgument argument;
768
memset(&argument, 0, sizeof(argument));
769
SolarisLwp lwp_lister(getpid());
770
argument.lwp_lister = &lwp_lister;
771
argument.minidump_writer = &minidump_writer;
772
argument.requester_pid = getpid();
773
argument.crashed_lwpid = pthread_self();
774
argument.signo = signo;
775
argument.sighandler_ebp = sighandler_ebp;
776
argument.sig_ctx = NULL;
778
pthread_create(&handler_thread, NULL, Write, (void *)&argument);
779
pthread_join(handler_thread, NULL);
786
} // namespace google_breakpad