Skip to content

Commit 88c0a25

Browse files
Abseil Teamcopybara-github
authored andcommitted
Remove the legacy stateless symbol decorator API.
PiperOrigin-RevId: 884958234 Change-Id: I288a4b143718a155663669b7d2e4a24a89d754ec
1 parent e8f3bb2 commit 88c0a25

4 files changed

Lines changed: 0 additions & 170 deletions

File tree

absl/debugging/internal/symbolize.h

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -78,46 +78,6 @@ namespace absl {
7878
ABSL_NAMESPACE_BEGIN
7979
namespace debugging_internal {
8080

81-
// Legacy stateless symbol decorator API. Will be removed soon.
82-
struct SymbolDecoratorArgs {
83-
// The program counter we are getting symbolic name for.
84-
const void *pc;
85-
// 0 for main executable, load address for shared libraries.
86-
ptrdiff_t relocation;
87-
// Read-only file descriptor for ELF image covering "pc",
88-
// or -1 if no such ELF image exists in /proc/self/maps.
89-
int fd;
90-
// Output buffer, size.
91-
// Note: the buffer may not be empty -- default symbolizer may have already
92-
// produced some output, and earlier decorators may have adorned it in
93-
// some way. You are free to replace or augment the contents (within the
94-
// symbol_buf_size limit).
95-
char *const symbol_buf;
96-
size_t symbol_buf_size;
97-
// Temporary scratch space, size.
98-
// Use that space in preference to allocating your own stack buffer to
99-
// conserve stack.
100-
char *const tmp_buf;
101-
size_t tmp_buf_size;
102-
// User-provided argument
103-
void* arg;
104-
};
105-
using LegacySymbolDecorator = void (*)(const SymbolDecoratorArgs *);
106-
107-
// Installs a function-pointer as a decorator. Returns a value less than zero
108-
// if the system cannot install the decorator. Otherwise, returns a unique
109-
// identifier corresponding to the decorator. This identifier can be used to
110-
// uninstall the decorator - See RemoveSymbolDecorator() below.
111-
int InstallSymbolDecorator(LegacySymbolDecorator decorator, void* arg);
112-
113-
// Removes a previously installed function-pointer decorator. Parameter "ticket"
114-
// is the return-value from calling InstallSymbolDecorator().
115-
bool RemoveSymbolDecorator(int ticket);
116-
117-
// Remove all installed decorators. Returns true if successful, false if
118-
// symbolization is currently in progress.
119-
bool RemoveAllSymbolDecorators();
120-
12181
class SymbolDecorator;
12282

12383
class SymbolDecoratorDeleter {

absl/debugging/symbolize_elf.inc

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,6 @@ inline constexpr bool kPlatformUsesOPDSections = false;
146146
// pointers and the first one is the function's entry.
147147
const size_t kFunctionDescriptorSize = sizeof(void *) * 2;
148148

149-
const int kMaxDecorators = 10; // Seems like a reasonable upper limit.
150-
151-
struct InstalledSymbolDecorator {
152-
LegacySymbolDecorator fn;
153-
void *arg;
154-
int ticket;
155-
};
156-
157-
int g_num_decorators;
158-
InstalledSymbolDecorator g_decorators[kMaxDecorators];
159-
160149
std::atomic<SymbolDecorator::Factory*> g_decorator_factory = nullptr;
161150

162151
struct FileMappingHint {
@@ -166,16 +155,6 @@ struct FileMappingHint {
166155
const char *filename;
167156
};
168157

169-
// Protects g_decorators.
170-
// We are using SpinLock and not a Mutex here, because we may be called
171-
// from inside Mutex::Lock itself, and it prohibits recursive calls.
172-
// This happens in e.g. base/stacktrace_syscall_unittest.
173-
// Moreover, we are using only try_lock(), if the decorator list
174-
// is being modified (is busy), we skip all decorators, and possibly
175-
// loose some info. Sorry, that's the best we could do.
176-
ABSL_CONST_INIT absl::base_internal::SpinLock g_decorators_mu(
177-
absl::base_internal::SCHEDULE_KERNEL_ONLY);
178-
179158
const int kMaxFileMappingHints = 8;
180159
int g_num_file_mapping_hints;
181160
FileMappingHint g_file_mapping_hints[kMaxFileMappingHints];
@@ -1507,7 +1486,6 @@ static bool MaybeInitializeObjFile(
15071486
const char *Symbolizer::GetUncachedSymbol(const void *pc) {
15081487
ObjFile *const obj = FindObjFile(pc, 1);
15091488
ptrdiff_t relocation = 0;
1510-
int fd = -1;
15111489
if (obj != nullptr) {
15121490
if (MaybeInitializeObjFile(obj, decorator_factory_)) {
15131491
const size_t start_addr = reinterpret_cast<size_t>(obj->start_addr);
@@ -1549,7 +1527,6 @@ const char *Symbolizer::GetUncachedSymbol(const void *pc) {
15491527
}
15501528
}
15511529

1552-
fd = obj->fd;
15531530
if (GetSymbolFromObjectFile(*obj, pc, relocation, symbol_buf_,
15541531
sizeof(symbol_buf_), tmp_buf_,
15551532
sizeof(tmp_buf_)) == SYMBOL_FOUND) {
@@ -1574,18 +1551,6 @@ const char *Symbolizer::GetUncachedSymbol(const void *pc) {
15741551
#endif
15751552
}
15761553

1577-
if (g_decorators_mu.try_lock()) {
1578-
if (g_num_decorators > 0) {
1579-
SymbolDecoratorArgs decorator_args = {
1580-
pc, relocation, fd, symbol_buf_, sizeof(symbol_buf_),
1581-
tmp_buf_, sizeof(tmp_buf_), nullptr};
1582-
for (int i = 0; i < g_num_decorators; ++i) {
1583-
decorator_args.arg = g_decorators[i].arg;
1584-
g_decorators[i].fn(&decorator_args);
1585-
}
1586-
}
1587-
g_decorators_mu.unlock();
1588-
}
15891554
if (obj != nullptr && obj->decorator != nullptr) {
15901555
obj->decorator->Decorate(pc, relocation, symbol_buf_, sizeof(symbol_buf_),
15911556
tmp_buf_, sizeof(tmp_buf_));
@@ -1633,55 +1598,6 @@ const char *Symbolizer::GetSymbol(const void *pc) {
16331598
#endif
16341599
}
16351600

1636-
bool RemoveAllSymbolDecorators() {
1637-
SetSymbolDecoratorFactory(nullptr);
1638-
1639-
if (!g_decorators_mu.try_lock()) {
1640-
// Someone else is using decorators. Get out.
1641-
return false;
1642-
}
1643-
g_num_decorators = 0;
1644-
g_decorators_mu.unlock();
1645-
return true;
1646-
}
1647-
1648-
bool RemoveSymbolDecorator(int ticket) {
1649-
if (!g_decorators_mu.try_lock()) {
1650-
// Someone else is using decorators. Get out.
1651-
return false;
1652-
}
1653-
for (int i = 0; i < g_num_decorators; ++i) {
1654-
if (g_decorators[i].ticket == ticket) {
1655-
while (i < g_num_decorators - 1) {
1656-
g_decorators[i] = g_decorators[i + 1];
1657-
++i;
1658-
}
1659-
g_num_decorators = i;
1660-
break;
1661-
}
1662-
}
1663-
g_decorators_mu.unlock();
1664-
return true; // Decorator is known to be removed.
1665-
}
1666-
1667-
int InstallSymbolDecorator(LegacySymbolDecorator decorator, void *arg) {
1668-
static int ticket = 0;
1669-
1670-
if (!g_decorators_mu.try_lock()) {
1671-
// Someone else is using decorators. Get out.
1672-
return -2;
1673-
}
1674-
int ret = ticket;
1675-
if (g_num_decorators >= kMaxDecorators) {
1676-
ret = -1;
1677-
} else {
1678-
g_decorators[g_num_decorators] = {decorator, arg, ticket++};
1679-
++g_num_decorators;
1680-
}
1681-
g_decorators_mu.unlock();
1682-
return ret;
1683-
}
1684-
16851601
SymbolDecorator::Factory* SetSymbolDecoratorFactory(
16861602
SymbolDecorator::Factory* factory) {
16871603
return g_decorator_factory.exchange(factory, std::memory_order_acq_rel);

absl/debugging/symbolize_test.cc

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -375,48 +375,6 @@ TEST(Symbolize, SymbolizeWithMultipleMaps) {
375375
}
376376
}
377377

378-
// Appends string(*args->arg) to args->symbol_buf.
379-
static void DummySymbolDecorator(
380-
const absl::debugging_internal::SymbolDecoratorArgs *args) {
381-
std::string *message = static_cast<std::string *>(args->arg);
382-
strncat(args->symbol_buf, message->c_str(),
383-
args->symbol_buf_size - strlen(args->symbol_buf) - 1);
384-
}
385-
386-
TEST(Symbolize, InstallAndRemoveSymbolDecorators) {
387-
int ticket_a;
388-
std::string a_message("a");
389-
EXPECT_GE(ticket_a = absl::debugging_internal::InstallSymbolDecorator(
390-
DummySymbolDecorator, &a_message),
391-
0);
392-
393-
int ticket_b;
394-
std::string b_message("b");
395-
EXPECT_GE(ticket_b = absl::debugging_internal::InstallSymbolDecorator(
396-
DummySymbolDecorator, &b_message),
397-
0);
398-
399-
int ticket_c;
400-
std::string c_message("c");
401-
EXPECT_GE(ticket_c = absl::debugging_internal::InstallSymbolDecorator(
402-
DummySymbolDecorator, &c_message),
403-
0);
404-
405-
// Use addresses 4 and 8 here to ensure that we always use valid addresses
406-
// even on systems that require instructions to be 32-bit aligned.
407-
char *address = reinterpret_cast<char *>(4);
408-
EXPECT_STREQ("abc", TrySymbolize(address));
409-
410-
EXPECT_TRUE(absl::debugging_internal::RemoveSymbolDecorator(ticket_b));
411-
412-
EXPECT_STREQ("ac", TrySymbolize(address + 4));
413-
414-
// Cleanup: remove all remaining decorators so other stack traces don't
415-
// get mystery "ac" decoration.
416-
EXPECT_TRUE(absl::debugging_internal::RemoveSymbolDecorator(ticket_a));
417-
EXPECT_TRUE(absl::debugging_internal::RemoveSymbolDecorator(ticket_c));
418-
}
419-
420378
template <char C>
421379
class TestSymbolDecorator final
422380
: public absl::debugging_internal::SymbolDecorator {

absl/debugging/symbolize_unimplemented.inc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ ABSL_NAMESPACE_BEGIN
2121

2222
namespace debugging_internal {
2323

24-
int InstallSymbolDecorator(LegacySymbolDecorator, void*) { return -1; }
25-
bool RemoveSymbolDecorator(int) { return false; }
26-
bool RemoveAllSymbolDecorators(void) { return false; }
27-
2824
SymbolDecorator::Factory* SetSymbolDecoratorFactory(SymbolDecorator::Factory*) {
2925
return nullptr;
3026
}

0 commit comments

Comments
 (0)