OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2013 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include <assert.h> | 7 #include <assert.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <string.h> | 9 #include <string.h> |
10 | 10 |
11 #include "native_client/src/include/nacl/nacl_minidump.h" | 11 #include "native_client/src/include/nacl/nacl_minidump.h" |
| 12 #include "native_client/src/untrusted/minidump_generator/build_id.h" |
12 | 13 |
13 | 14 |
14 const char *g_minidump_filename; | 15 const char *g_minidump_filename; |
15 | 16 |
16 | 17 |
| 18 /* TODO(mseaborn): Make build IDs work in the other toolchains. */ |
| 19 #if defined(__arm__) |
| 20 # define BUILD_ID_WORKS 1 |
| 21 #else |
| 22 # define BUILD_ID_WORKS 0 |
| 23 #endif |
| 24 |
17 static void crash_callback(const void *minidump_data, size_t size) { | 25 static void crash_callback(const void *minidump_data, size_t size) { |
18 assert(size != 0); | 26 assert(size != 0); |
19 FILE *fp = fopen(g_minidump_filename, "wb"); | 27 FILE *fp = fopen(g_minidump_filename, "wb"); |
20 assert(fp != NULL); | 28 assert(fp != NULL); |
21 int written = fwrite(minidump_data, 1, size, fp); | 29 int written = fwrite(minidump_data, 1, size, fp); |
22 assert(written == size); | 30 assert(written == size); |
23 int rc = fclose(fp); | 31 int rc = fclose(fp); |
24 assert(rc == 0); | 32 assert(rc == 0); |
25 | 33 |
26 fprintf(stderr, "** intended_exit_status=0\n"); | 34 fprintf(stderr, "** intended_exit_status=0\n"); |
(...skipping 13 matching lines...) Expand all Loading... |
40 | 48 |
41 __attribute__((noinline)) | 49 __attribute__((noinline)) |
42 void crash_wrapper2(void) { | 50 void crash_wrapper2(void) { |
43 crash_wrapper1(); | 51 crash_wrapper1(); |
44 } | 52 } |
45 | 53 |
46 int main(int argc, char **argv) { | 54 int main(int argc, char **argv) { |
47 assert(argc == 2); | 55 assert(argc == 2); |
48 g_minidump_filename = argv[1]; | 56 g_minidump_filename = argv[1]; |
49 | 57 |
50 /* | 58 const char *id_data; |
51 * TODO(mseaborn): Extract the real build ID from the nexe at run | 59 size_t id_size; |
52 * time. This will require linker support. | 60 int got_build_id = nacl_get_build_id(&id_data, &id_size); |
53 */ | 61 if (BUILD_ID_WORKS) { |
54 uint8_t dummy_build_id[NACL_MINIDUMP_BUILD_ID_SIZE]; | 62 assert(got_build_id); |
55 memset(dummy_build_id, 0x12, sizeof(dummy_build_id)); | 63 assert(id_data != NULL); |
| 64 assert(id_size == 20); /* ld uses SHA1 hash by default. */ |
| 65 } else { |
| 66 uint8_t dummy_build_id[NACL_MINIDUMP_BUILD_ID_SIZE]; |
| 67 memset(dummy_build_id, 0x12, sizeof(dummy_build_id)); |
| 68 nacl_minidump_set_module_build_id(dummy_build_id); |
| 69 } |
56 | 70 |
57 nacl_minidump_set_callback(crash_callback); | 71 nacl_minidump_set_callback(crash_callback); |
58 nacl_minidump_set_module_name("minidump_test.nexe"); | 72 nacl_minidump_set_module_name("minidump_test.nexe"); |
59 nacl_minidump_set_module_build_id(dummy_build_id); | |
60 nacl_minidump_register_crash_handler(); | 73 nacl_minidump_register_crash_handler(); |
61 | 74 |
62 /* Cause crash. */ | 75 /* Cause crash. */ |
63 crash_wrapper2(); | 76 crash_wrapper2(); |
64 | 77 |
65 /* Should not reach here. */ | 78 /* Should not reach here. */ |
66 return 1; | 79 return 1; |
67 } | 80 } |
OLD | NEW |