bloaty/third_party/abseil-cpp/absl/debugging/symbolize_test.cc
Go to the documentation of this file.
1 // Copyright 2018 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "absl/debugging/symbolize.h"
16 
17 #ifndef _WIN32
18 #include <fcntl.h>
19 #include <sys/mman.h>
20 #endif
21 
22 #include <cstring>
23 #include <iostream>
24 #include <memory>
25 
26 #include "gmock/gmock.h"
27 #include "gtest/gtest.h"
28 #include "absl/base/attributes.h"
29 #include "absl/base/casts.h"
30 #include "absl/base/config.h"
31 #include "absl/base/internal/per_thread_tls.h"
32 #include "absl/base/internal/raw_logging.h"
33 #include "absl/base/optimization.h"
34 #include "absl/debugging/internal/stack_consumption.h"
35 #include "absl/memory/memory.h"
36 #include "absl/strings/string_view.h"
37 
38 using testing::Contains;
39 
40 #ifdef _WIN32
41 #define ABSL_SYMBOLIZE_TEST_NOINLINE __declspec(noinline)
42 #else
43 #define ABSL_SYMBOLIZE_TEST_NOINLINE ABSL_ATTRIBUTE_NOINLINE
44 #endif
45 
46 // Functions to symbolize. Use C linkage to avoid mangled names.
47 extern "C" {
49  // The next line makes this a unique function to prevent the compiler from
50  // folding identical functions together.
51  volatile int x = __LINE__;
52  static_cast<void>(x);
54 }
55 
57  // The next line makes this a unique function to prevent the compiler from
58  // folding identical functions together.
59  volatile int x = __LINE__;
60  static_cast<void>(x);
62 }
63 } // extern "C"
64 
65 struct Foo {
66  static void func(int x);
67 };
68 
69 // A C++ method that should have a mangled name.
71  // The next line makes this a unique function to prevent the compiler from
72  // folding identical functions together.
73  volatile int x = __LINE__;
74  static_cast<void>(x);
76 }
77 
78 // Create functions that will remain in different text sections in the
79 // final binary when linker option "-z,keep-text-section-prefix" is used.
80 int ABSL_ATTRIBUTE_SECTION_VARIABLE(.text.unlikely) unlikely_func() {
81  return 0;
82 }
83 
84 int ABSL_ATTRIBUTE_SECTION_VARIABLE(.text.hot) hot_func() {
85  return 0;
86 }
87 
88 int ABSL_ATTRIBUTE_SECTION_VARIABLE(.text.startup) startup_func() {
89  return 0;
90 }
91 
92 int ABSL_ATTRIBUTE_SECTION_VARIABLE(.text.exit) exit_func() {
93  return 0;
94 }
95 
96 int /*ABSL_ATTRIBUTE_SECTION_VARIABLE(.text)*/ regular_func() {
97  return 0;
98 }
99 
100 // Thread-local data may confuse the symbolizer, ensure that it does not.
101 // Variable sizes and order are important.
102 #if ABSL_PER_THREAD_TLS
103 static ABSL_PER_THREAD_TLS_KEYWORD char symbolize_test_thread_small[1];
104 static ABSL_PER_THREAD_TLS_KEYWORD char
105  symbolize_test_thread_big[2 * 1024 * 1024];
106 #endif
107 
108 #if !defined(__EMSCRIPTEN__)
109 // Used below to hopefully inhibit some compiler/linker optimizations
110 // that may remove kHpageTextPadding, kPadding0, and kPadding1 from
111 // the binary.
112 static volatile bool volatile_bool = false;
113 
114 // Force the binary to be large enough that a THP .text remap will succeed.
115 static constexpr size_t kHpageSize = 1 << 21;
116 const char kHpageTextPadding[kHpageSize * 4] ABSL_ATTRIBUTE_SECTION_VARIABLE(
117  .text) = "";
118 #endif // !defined(__EMSCRIPTEN__)
119 
120 static char try_symbolize_buffer[4096];
121 
122 // A wrapper function for absl::Symbolize() to make the unit test simple. The
123 // limit must be < sizeof(try_symbolize_buffer). Returns null if
124 // absl::Symbolize() returns false, otherwise returns try_symbolize_buffer with
125 // the result of absl::Symbolize().
126 static const char *TrySymbolizeWithLimit(void *pc, int limit) {
127  ABSL_RAW_CHECK(limit <= sizeof(try_symbolize_buffer),
128  "try_symbolize_buffer is too small");
129 
130  // Use the heap to facilitate heap and buffer sanitizer tools.
131  auto heap_buffer = absl::make_unique<char[]>(sizeof(try_symbolize_buffer));
132  bool found = absl::Symbolize(pc, heap_buffer.get(), limit);
133  if (found) {
134  ABSL_RAW_CHECK(strnlen(heap_buffer.get(), limit) < limit,
135  "absl::Symbolize() did not properly terminate the string");
136  strncpy(try_symbolize_buffer, heap_buffer.get(),
137  sizeof(try_symbolize_buffer) - 1);
138  try_symbolize_buffer[sizeof(try_symbolize_buffer) - 1] = '\0';
139  }
140 
141  return found ? try_symbolize_buffer : nullptr;
142 }
143 
144 // A wrapper for TrySymbolizeWithLimit(), with a large limit.
145 static const char *TrySymbolize(void *pc) {
146  return TrySymbolizeWithLimit(pc, sizeof(try_symbolize_buffer));
147 }
148 
149 #if defined(ABSL_INTERNAL_HAVE_ELF_SYMBOLIZE) || \
150  defined(ABSL_INTERNAL_HAVE_DARWIN_SYMBOLIZE)
151 
152 TEST(Symbolize, Cached) {
153  // Compilers should give us pointers to them.
154  EXPECT_STREQ("nonstatic_func", TrySymbolize((void *)(&nonstatic_func)));
155 
156  // The name of an internal linkage symbol is not specified; allow either a
157  // mangled or an unmangled name here.
158  const char *static_func_symbol = TrySymbolize((void *)(&static_func));
159  EXPECT_TRUE(strcmp("static_func", static_func_symbol) == 0 ||
160  strcmp("static_func()", static_func_symbol) == 0);
161 
162  EXPECT_TRUE(nullptr == TrySymbolize(nullptr));
163 }
164 
165 TEST(Symbolize, Truncation) {
166  constexpr char kNonStaticFunc[] = "nonstatic_func";
167  EXPECT_STREQ("nonstatic_func",
169  strlen(kNonStaticFunc) + 1));
170  EXPECT_STREQ("nonstatic_...",
172  strlen(kNonStaticFunc) + 0));
173  EXPECT_STREQ("nonstatic...",
175  strlen(kNonStaticFunc) - 1));
176  EXPECT_STREQ("n...", TrySymbolizeWithLimit((void *)(&nonstatic_func), 5));
177  EXPECT_STREQ("...", TrySymbolizeWithLimit((void *)(&nonstatic_func), 4));
178  EXPECT_STREQ("..", TrySymbolizeWithLimit((void *)(&nonstatic_func), 3));
181  EXPECT_EQ(nullptr, TrySymbolizeWithLimit((void *)(&nonstatic_func), 0));
182 }
183 
184 TEST(Symbolize, SymbolizeWithDemangling) {
185  Foo::func(100);
186  EXPECT_STREQ("Foo::func()", TrySymbolize((void *)(&Foo::func)));
187 }
188 
189 TEST(Symbolize, SymbolizeSplitTextSections) {
190  EXPECT_STREQ("unlikely_func()", TrySymbolize((void *)(&unlikely_func)));
191  EXPECT_STREQ("hot_func()", TrySymbolize((void *)(&hot_func)));
192  EXPECT_STREQ("startup_func()", TrySymbolize((void *)(&startup_func)));
193  EXPECT_STREQ("exit_func()", TrySymbolize((void *)(&exit_func)));
194  EXPECT_STREQ("regular_func()", TrySymbolize((void *)(&regular_func)));
195 }
196 
197 // Tests that verify that Symbolize stack footprint is within some limit.
198 #ifdef ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION
199 
200 static void *g_pc_to_symbolize;
201 static char g_symbolize_buffer[4096];
202 static char *g_symbolize_result;
203 
204 static void SymbolizeSignalHandler(int signo) {
205  if (absl::Symbolize(g_pc_to_symbolize, g_symbolize_buffer,
206  sizeof(g_symbolize_buffer))) {
207  g_symbolize_result = g_symbolize_buffer;
208  } else {
209  g_symbolize_result = nullptr;
210  }
211 }
212 
213 // Call Symbolize and figure out the stack footprint of this call.
214 static const char *SymbolizeStackConsumption(void *pc, int *stack_consumed) {
215  g_pc_to_symbolize = pc;
216  *stack_consumed = absl::debugging_internal::GetSignalHandlerStackConsumption(
217  SymbolizeSignalHandler);
218  return g_symbolize_result;
219 }
220 
221 static int GetStackConsumptionUpperLimit() {
222  // Symbolize stack consumption should be within 2kB.
223  int stack_consumption_upper_limit = 2048;
224 #if defined(ABSL_HAVE_ADDRESS_SANITIZER) || \
225  defined(ABSL_HAVE_MEMORY_SANITIZER) || defined(ABSL_HAVE_THREAD_SANITIZER)
226  // Account for sanitizer instrumentation requiring additional stack space.
227  stack_consumption_upper_limit *= 5;
228 #endif
229  return stack_consumption_upper_limit;
230 }
231 
232 TEST(Symbolize, SymbolizeStackConsumption) {
233  int stack_consumed = 0;
234 
235  const char *symbol =
236  SymbolizeStackConsumption((void *)(&nonstatic_func), &stack_consumed);
237  EXPECT_STREQ("nonstatic_func", symbol);
238  EXPECT_GT(stack_consumed, 0);
239  EXPECT_LT(stack_consumed, GetStackConsumptionUpperLimit());
240 
241  // The name of an internal linkage symbol is not specified; allow either a
242  // mangled or an unmangled name here.
243  symbol = SymbolizeStackConsumption((void *)(&static_func), &stack_consumed);
244  EXPECT_TRUE(strcmp("static_func", symbol) == 0 ||
245  strcmp("static_func()", symbol) == 0);
246  EXPECT_GT(stack_consumed, 0);
247  EXPECT_LT(stack_consumed, GetStackConsumptionUpperLimit());
248 }
249 
250 TEST(Symbolize, SymbolizeWithDemanglingStackConsumption) {
251  Foo::func(100);
252  int stack_consumed = 0;
253 
254  const char *symbol =
255  SymbolizeStackConsumption((void *)(&Foo::func), &stack_consumed);
256 
257  EXPECT_STREQ("Foo::func()", symbol);
258  EXPECT_GT(stack_consumed, 0);
259  EXPECT_LT(stack_consumed, GetStackConsumptionUpperLimit());
260 }
261 
262 #endif // ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION
263 
264 #ifndef ABSL_INTERNAL_HAVE_DARWIN_SYMBOLIZE
265 // Use a 64K page size for PPC.
266 const size_t kPageSize = 64 << 10;
267 // We place a read-only symbols into the .text section and verify that we can
268 // symbolize them and other symbols after remapping them.
269 const char kPadding0[kPageSize * 4] ABSL_ATTRIBUTE_SECTION_VARIABLE(.text) =
270  "";
271 const char kPadding1[kPageSize * 4] ABSL_ATTRIBUTE_SECTION_VARIABLE(.text) =
272  "";
273 
274 static int FilterElfHeader(struct dl_phdr_info *info, size_t size, void *data) {
275  for (int i = 0; i < info->dlpi_phnum; i++) {
276  if (info->dlpi_phdr[i].p_type == PT_LOAD &&
277  info->dlpi_phdr[i].p_flags == (PF_R | PF_X)) {
278  const void *const vaddr =
279  absl::bit_cast<void *>(info->dlpi_addr + info->dlpi_phdr[i].p_vaddr);
280  const auto segsize = info->dlpi_phdr[i].p_memsz;
281 
282  const char *self_exe;
283  if (info->dlpi_name != nullptr && info->dlpi_name[0] != '\0') {
284  self_exe = info->dlpi_name;
285  } else {
286  self_exe = "/proc/self/exe";
287  }
288 
289  absl::debugging_internal::RegisterFileMappingHint(
290  vaddr, reinterpret_cast<const char *>(vaddr) + segsize,
291  info->dlpi_phdr[i].p_offset, self_exe);
292 
293  return 1;
294  }
295  }
296 
297  return 1;
298 }
299 
300 TEST(Symbolize, SymbolizeWithMultipleMaps) {
301  // Force kPadding0 and kPadding1 to be linked in.
302  if (volatile_bool) {
303  ABSL_RAW_LOG(INFO, "%s", kPadding0);
304  ABSL_RAW_LOG(INFO, "%s", kPadding1);
305  }
306 
307  // Verify we can symbolize everything.
308  char buf[512];
309  memset(buf, 0, sizeof(buf));
310  absl::Symbolize(kPadding0, buf, sizeof(buf));
311  EXPECT_STREQ("kPadding0", buf);
312 
313  memset(buf, 0, sizeof(buf));
314  absl::Symbolize(kPadding1, buf, sizeof(buf));
315  EXPECT_STREQ("kPadding1", buf);
316 
317  // Specify a hint for the executable segment.
318  dl_iterate_phdr(FilterElfHeader, nullptr);
319 
320  // Reload at least one page out of kPadding0, kPadding1
321  const char *ptrs[] = {kPadding0, kPadding1};
322 
323  for (const char *ptr : ptrs) {
324  const int kMapFlags = MAP_ANONYMOUS | MAP_PRIVATE;
325  void *addr = mmap(nullptr, kPageSize, PROT_READ, kMapFlags, 0, 0);
326  ASSERT_NE(addr, MAP_FAILED);
327 
328  // kPadding[0-1] is full of zeroes, so we can remap anywhere within it, but
329  // we ensure there is at least a full page of padding.
330  void *remapped = reinterpret_cast<void *>(
331  reinterpret_cast<uintptr_t>(ptr + kPageSize) & ~(kPageSize - 1ULL));
332 
333  const int kMremapFlags = (MREMAP_MAYMOVE | MREMAP_FIXED);
334  void *ret = mremap(addr, kPageSize, kPageSize, kMremapFlags, remapped);
335  ASSERT_NE(ret, MAP_FAILED);
336  }
337 
338  // Invalidate the symbolization cache so we are forced to rely on the hint.
339  absl::Symbolize(nullptr, buf, sizeof(buf));
340 
341  // Verify we can still symbolize.
342  const char *expected[] = {"kPadding0", "kPadding1"};
343  const size_t offsets[] = {0, kPageSize, 2 * kPageSize, 3 * kPageSize};
344 
345  for (int i = 0; i < 2; i++) {
346  for (size_t offset : offsets) {
347  memset(buf, 0, sizeof(buf));
348  absl::Symbolize(ptrs[i] + offset, buf, sizeof(buf));
349  EXPECT_STREQ(expected[i], buf);
350  }
351  }
352 }
353 
354 // Appends string(*args->arg) to args->symbol_buf.
355 static void DummySymbolDecorator(
356  const absl::debugging_internal::SymbolDecoratorArgs *args) {
357  std::string *message = static_cast<std::string *>(args->arg);
358  strncat(args->symbol_buf, message->c_str(),
359  args->symbol_buf_size - strlen(args->symbol_buf) - 1);
360 }
361 
362 TEST(Symbolize, InstallAndRemoveSymbolDecorators) {
363  int ticket_a;
364  std::string a_message("a");
365  EXPECT_GE(ticket_a = absl::debugging_internal::InstallSymbolDecorator(
366  DummySymbolDecorator, &a_message),
367  0);
368 
369  int ticket_b;
370  std::string b_message("b");
371  EXPECT_GE(ticket_b = absl::debugging_internal::InstallSymbolDecorator(
372  DummySymbolDecorator, &b_message),
373  0);
374 
375  int ticket_c;
376  std::string c_message("c");
377  EXPECT_GE(ticket_c = absl::debugging_internal::InstallSymbolDecorator(
378  DummySymbolDecorator, &c_message),
379  0);
380 
381  char *address = reinterpret_cast<char *>(1);
382  EXPECT_STREQ("abc", TrySymbolize(address++));
383 
384  EXPECT_TRUE(absl::debugging_internal::RemoveSymbolDecorator(ticket_b));
385 
386  EXPECT_STREQ("ac", TrySymbolize(address++));
387 
388  // Cleanup: remove all remaining decorators so other stack traces don't
389  // get mystery "ac" decoration.
390  EXPECT_TRUE(absl::debugging_internal::RemoveSymbolDecorator(ticket_a));
391  EXPECT_TRUE(absl::debugging_internal::RemoveSymbolDecorator(ticket_c));
392 }
393 
394 // Some versions of Clang with optimizations enabled seem to be able
395 // to optimize away the .data section if no variables live in the
396 // section. This variable should get placed in the .data section, and
397 // the test below checks for the existence of a .data section.
398 static int in_data_section = 1;
399 
401  int fd = TEMP_FAILURE_RETRY(open("/proc/self/exe", O_RDONLY));
402  ASSERT_NE(fd, -1);
403 
404  std::vector<std::string> sections;
406  fd, [&sections](const absl::string_view name, const ElfW(Shdr) &) {
407  sections.emplace_back(name);
408  return true;
409  }));
410 
411  // Check for the presence of common section names.
412  EXPECT_THAT(sections, Contains(".text"));
413  EXPECT_THAT(sections, Contains(".rodata"));
414  EXPECT_THAT(sections, Contains(".bss"));
415  ++in_data_section;
416  EXPECT_THAT(sections, Contains(".data"));
417 
418  close(fd);
419 }
420 #endif // !ABSL_INTERNAL_HAVE_DARWIN_SYMBOLIZE
421 
422 // x86 specific tests. Uses some inline assembler.
423 extern "C" {
424 inline void *ABSL_ATTRIBUTE_ALWAYS_INLINE inline_func() {
425  void *pc = nullptr;
426 #if defined(__i386__)
427  __asm__ __volatile__("call 1f;\n 1: pop %[PC]" : [ PC ] "=r"(pc));
428 #elif defined(__x86_64__)
429  __asm__ __volatile__("leaq 0(%%rip),%[PC];\n" : [ PC ] "=r"(pc));
430 #endif
431  return pc;
432 }
433 
434 void *ABSL_ATTRIBUTE_NOINLINE non_inline_func() {
435  void *pc = nullptr;
436 #if defined(__i386__)
437  __asm__ __volatile__("call 1f;\n 1: pop %[PC]" : [ PC ] "=r"(pc));
438 #elif defined(__x86_64__)
439  __asm__ __volatile__("leaq 0(%%rip),%[PC];\n" : [ PC ] "=r"(pc));
440 #endif
441  return pc;
442 }
443 
444 void ABSL_ATTRIBUTE_NOINLINE TestWithPCInsideNonInlineFunction() {
445 #if defined(ABSL_HAVE_ATTRIBUTE_NOINLINE) && \
446  (defined(__i386__) || defined(__x86_64__))
447  void *pc = non_inline_func();
448  const char *symbol = TrySymbolize(pc);
449  ABSL_RAW_CHECK(symbol != nullptr, "TestWithPCInsideNonInlineFunction failed");
450  ABSL_RAW_CHECK(strcmp(symbol, "non_inline_func") == 0,
451  "TestWithPCInsideNonInlineFunction failed");
452  std::cout << "TestWithPCInsideNonInlineFunction passed" << std::endl;
453 #endif
454 }
455 
456 void ABSL_ATTRIBUTE_NOINLINE TestWithPCInsideInlineFunction() {
457 #if defined(ABSL_HAVE_ATTRIBUTE_ALWAYS_INLINE) && \
458  (defined(__i386__) || defined(__x86_64__))
459  void *pc = inline_func(); // Must be inlined.
460  const char *symbol = TrySymbolize(pc);
461  ABSL_RAW_CHECK(symbol != nullptr, "TestWithPCInsideInlineFunction failed");
462  ABSL_RAW_CHECK(strcmp(symbol, __FUNCTION__) == 0,
463  "TestWithPCInsideInlineFunction failed");
464  std::cout << "TestWithPCInsideInlineFunction passed" << std::endl;
465 #endif
466 }
467 }
468 
469 // Test with a return address.
470 void ABSL_ATTRIBUTE_NOINLINE TestWithReturnAddress() {
471 #if defined(ABSL_HAVE_ATTRIBUTE_NOINLINE)
472  void *return_address = __builtin_return_address(0);
473  const char *symbol = TrySymbolize(return_address);
474  ABSL_RAW_CHECK(symbol != nullptr, "TestWithReturnAddress failed");
475  ABSL_RAW_CHECK(strcmp(symbol, "main") == 0, "TestWithReturnAddress failed");
476  std::cout << "TestWithReturnAddress passed" << std::endl;
477 #endif
478 }
479 
480 #if defined(__arm__) && ABSL_HAVE_ATTRIBUTE(target)
481 // Test that we correctly identify bounds of Thumb functions on ARM.
482 //
483 // Thumb functions have the lowest-order bit set in their addresses in the ELF
484 // symbol table. This requires some extra logic to properly compute function
485 // bounds. To test this logic, nudge a Thumb function right up against an ARM
486 // function and try to symbolize the ARM function.
487 //
488 // A naive implementation will simply use the Thumb function's entry point as
489 // written in the symbol table and will therefore treat the Thumb function as
490 // extending one byte further in the instruction stream than it actually does.
491 // When asked to symbolize the start of the ARM function, it will identify an
492 // overlap between the Thumb and ARM functions, and it will return the name of
493 // the Thumb function.
494 //
495 // A correct implementation, on the other hand, will null out the lowest-order
496 // bit in the Thumb function's entry point. It will correctly compute the end of
497 // the Thumb function, it will find no overlap between the Thumb and ARM
498 // functions, and it will return the name of the ARM function.
499 
500 __attribute__((target("thumb"))) int ArmThumbOverlapThumb(int x) {
501  return x * x * x;
502 }
503 
504 __attribute__((target("arm"))) int ArmThumbOverlapArm(int x) {
505  return x * x * x;
506 }
507 
508 void ABSL_ATTRIBUTE_NOINLINE TestArmThumbOverlap() {
509 #if defined(ABSL_HAVE_ATTRIBUTE_NOINLINE)
510  const char *symbol = TrySymbolize((void *)&ArmThumbOverlapArm);
511  ABSL_RAW_CHECK(symbol != nullptr, "TestArmThumbOverlap failed");
512  ABSL_RAW_CHECK(strcmp("ArmThumbOverlapArm()", symbol) == 0,
513  "TestArmThumbOverlap failed");
514  std::cout << "TestArmThumbOverlap passed" << std::endl;
515 #endif
516 }
517 
518 #endif // defined(__arm__) && ABSL_HAVE_ATTRIBUTE(target)
519 
520 #elif defined(_WIN32)
521 #if !defined(ABSL_CONSUME_DLL)
522 
523 TEST(Symbolize, Basics) {
524  EXPECT_STREQ("nonstatic_func", TrySymbolize((void *)(&nonstatic_func)));
525 
526  // The name of an internal linkage symbol is not specified; allow either a
527  // mangled or an unmangled name here.
528  const char *static_func_symbol = TrySymbolize((void *)(&static_func));
529  ASSERT_TRUE(static_func_symbol != nullptr);
530  EXPECT_TRUE(strstr(static_func_symbol, "static_func") != nullptr);
531 
532  EXPECT_TRUE(nullptr == TrySymbolize(nullptr));
533 }
534 
535 TEST(Symbolize, Truncation) {
536  constexpr char kNonStaticFunc[] = "nonstatic_func";
537  EXPECT_STREQ("nonstatic_func",
539  strlen(kNonStaticFunc) + 1));
540  EXPECT_STREQ("nonstatic_...",
542  strlen(kNonStaticFunc) + 0));
543  EXPECT_STREQ("nonstatic...",
545  strlen(kNonStaticFunc) - 1));
546  EXPECT_STREQ("n...", TrySymbolizeWithLimit((void *)(&nonstatic_func), 5));
547  EXPECT_STREQ("...", TrySymbolizeWithLimit((void *)(&nonstatic_func), 4));
548  EXPECT_STREQ("..", TrySymbolizeWithLimit((void *)(&nonstatic_func), 3));
551  EXPECT_EQ(nullptr, TrySymbolizeWithLimit((void *)(&nonstatic_func), 0));
552 }
553 
554 TEST(Symbolize, SymbolizeWithDemangling) {
555  const char *result = TrySymbolize((void *)(&Foo::func));
556  ASSERT_TRUE(result != nullptr);
557  EXPECT_TRUE(strstr(result, "Foo::func") != nullptr) << result;
558 }
559 
560 #endif // !defined(ABSL_CONSUME_DLL)
561 #else // Symbolizer unimplemented
562 
563 TEST(Symbolize, Unimplemented) {
564  char buf[64];
565  EXPECT_FALSE(absl::Symbolize((void *)(&nonstatic_func), buf, sizeof(buf)));
566  EXPECT_FALSE(absl::Symbolize((void *)(&static_func), buf, sizeof(buf)));
567  EXPECT_FALSE(absl::Symbolize((void *)(&Foo::func), buf, sizeof(buf)));
568 }
569 
570 #endif
571 
572 int main(int argc, char **argv) {
573 #if !defined(__EMSCRIPTEN__)
574  // Make sure kHpageTextPadding is linked into the binary.
575  if (volatile_bool) {
576  ABSL_RAW_LOG(INFO, "%s", kHpageTextPadding);
577  }
578 #endif // !defined(__EMSCRIPTEN__)
579 
580 #if ABSL_PER_THREAD_TLS
581  // Touch the per-thread variables.
582  symbolize_test_thread_small[0] = 0;
583  symbolize_test_thread_big[0] = 0;
584 #endif
585 
587  testing::InitGoogleTest(&argc, argv);
588 
589 #if defined(ABSL_INTERNAL_HAVE_ELF_SYMBOLIZE) || \
590  defined(ABSL_INTERNAL_HAVE_DARWIN_SYMBOLIZE)
591  TestWithPCInsideInlineFunction();
592  TestWithPCInsideNonInlineFunction();
593  TestWithReturnAddress();
594 #if defined(__arm__) && ABSL_HAVE_ATTRIBUTE(target)
595  TestArmThumbOverlap();
596 #endif
597 #endif
598 
599  return RUN_ALL_TESTS();
600 }
EXPECT_FALSE
#define EXPECT_FALSE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1970
ptr
char * ptr
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:45
ABSL_ATTRIBUTE_ALWAYS_INLINE
#define ABSL_ATTRIBUTE_ALWAYS_INLINE
Definition: abseil-cpp/absl/base/attributes.h:105
ABSL_RAW_CHECK
#define ABSL_RAW_CHECK(condition, message)
Definition: abseil-cpp/absl/base/internal/raw_logging.h:59
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
ABSL_ATTRIBUTE_SECTION_VARIABLE
int ABSL_ATTRIBUTE_SECTION_VARIABLE(.text.unlikely) unlikely_func()
Definition: bloaty/third_party/abseil-cpp/absl/debugging/symbolize_test.cc:80
ASSERT_NE
#define ASSERT_NE(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2060
memset
return memset(p, 0, total)
EXPECT_THAT
#define EXPECT_THAT(value, matcher)
nonstatic_func
ABSL_SYMBOLIZE_TEST_NOINLINE void nonstatic_func()
Definition: bloaty/third_party/abseil-cpp/absl/debugging/symbolize_test.cc:48
TrySymbolizeWithLimit
static const char * TrySymbolizeWithLimit(void *pc, int limit)
Definition: bloaty/third_party/abseil-cpp/absl/debugging/symbolize_test.cc:126
main
int main(int argc, char **argv)
Definition: bloaty/third_party/abseil-cpp/absl/debugging/symbolize_test.cc:572
buf
voidpf void * buf
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
EXPECT_GT
#define EXPECT_GT(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2036
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
setup.name
name
Definition: setup.py:542
static_func
static ABSL_SYMBOLIZE_TEST_NOINLINE void static_func()
Definition: bloaty/third_party/abseil-cpp/absl/debugging/symbolize_test.cc:56
message
char * message
Definition: libuv/docs/code/tty-gravity/main.c:12
ABSL_ATTRIBUTE_NOINLINE
#define ABSL_ATTRIBUTE_NOINLINE
Definition: abseil-cpp/absl/base/attributes.h:112
PF_R
#define PF_R
Definition: elf_common.h:547
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:27
PT_LOAD
#define PT_LOAD
Definition: elf_common.h:511
bloat_diff.sections
list sections
Definition: bloat_diff.py:121
ULL
#define ULL(x)
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/coded_stream_unittest.cc:57
gen_server_registered_method_bad_client_test_body.text
def text
Definition: gen_server_registered_method_bad_client_test_body.py:50
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
xds_interop_client.int
int
Definition: xds_interop_client.py:113
kHpageSize
static constexpr size_t kHpageSize
Definition: bloaty/third_party/abseil-cpp/absl/debugging/symbolize_test.cc:115
bloaty::pe::ForEachSection
void ForEachSection(const PeFile &pe, Func &&section_func)
Definition: pe.cc:184
gen_stats_data.found
bool found
Definition: gen_stats_data.py:61
Foo
Definition: abseil-cpp/absl/debugging/symbolize_test.cc:65
python_utils.jobset.INFO
INFO
Definition: jobset.py:111
ABSL_SYMBOLIZE_TEST_NOINLINE
#define ABSL_SYMBOLIZE_TEST_NOINLINE
Definition: bloaty/third_party/abseil-cpp/absl/debugging/symbolize_test.cc:43
__attribute__
__attribute__(void) start
close
#define close
Definition: test-fs.c:48
ABSL_PER_THREAD_TLS_KEYWORD
#define ABSL_PER_THREAD_TLS_KEYWORD
Definition: abseil-cpp/absl/base/internal/per_thread_tls.h:48
try_symbolize_buffer
static char try_symbolize_buffer[4096]
Definition: bloaty/third_party/abseil-cpp/absl/debugging/symbolize_test.cc:120
x
int x
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3610
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
uintptr_t
_W64 unsigned int uintptr_t
Definition: stdint-msvc2008.h:119
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
TrySymbolize
static const char * TrySymbolize(void *pc)
Definition: bloaty/third_party/abseil-cpp/absl/debugging/symbolize_test.cc:145
absl::Symbolize
bool Symbolize(const void *pc, char *out, int out_size)
EXPECT_STREQ
#define EXPECT_STREQ(s1, s2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2095
absl::container_internal::internal_layout::Contains
absl::disjunction< std::is_same< T, Ts >... > Contains
Definition: abseil-cpp/absl/container/internal/layout.h:253
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6106
regular_func
int regular_func()
Definition: bloaty/third_party/abseil-cpp/absl/debugging/symbolize_test.cc:96
ABSL_BLOCK_TAIL_CALL_OPTIMIZATION
#define ABSL_BLOCK_TAIL_CALL_OPTIMIZATION()
Definition: abseil-cpp/absl/base/optimization.h:55
ret
UniquePtr< SSL_SESSION > ret
Definition: ssl_x509.cc:1029
EXPECT_LT
#define EXPECT_LT(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2032
absl::InitializeSymbolizer
ABSL_NAMESPACE_BEGIN void InitializeSymbolizer(const char *argv0)
ASSERT_TRUE
#define ASSERT_TRUE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1973
TEST
TEST(Symbolize, Unimplemented)
Definition: bloaty/third_party/abseil-cpp/absl/debugging/symbolize_test.cc:563
EXPECT_GE
#define EXPECT_GE(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2034
EXPECT_TRUE
#define EXPECT_TRUE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1967
open
#define open
Definition: test-fs.c:46
strnlen
size_t strnlen(const char *str, size_t maxlen)
Definition: os390-syscalls.c:554
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
PF_X
#define PF_X
Definition: elf_common.h:545
Foo::func
static void func(int x)
Definition: abseil-cpp/absl/debugging/symbolize_test.cc:70
testing::Contains
internal::ContainsMatcher< M > Contains(M matcher)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:9101
ABSL_RAW_LOG
#define ABSL_RAW_LOG(severity,...)
Definition: abseil-cpp/absl/base/internal/raw_logging.h:44
setup.target
target
Definition: third_party/bloaty/third_party/protobuf/python/setup.py:179
addr
struct sockaddr_in addr
Definition: libuv/docs/code/tcp-echo-server/main.c:10
volatile_bool
static volatile bool volatile_bool
Definition: bloaty/third_party/abseil-cpp/absl/debugging/symbolize_test.cc:112
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
offset
voidpf uLong offset
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:142


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:24