forked from OSchip/llvm-project
[Sanitizer] Get rid of unnecessary allocations in StripModuleName. NFC.
llvm-svn: 221287
This commit is contained in:
parent
404ab37e8b
commit
26ca05ad96
|
@ -155,6 +155,14 @@ const char *StripPathPrefix(const char *filepath,
|
|||
return pos;
|
||||
}
|
||||
|
||||
const char *StripModuleName(const char *module) {
|
||||
if (module == 0)
|
||||
return 0;
|
||||
if (const char *slash_pos = internal_strrchr(module, '/'))
|
||||
return slash_pos + 1;
|
||||
return module;
|
||||
}
|
||||
|
||||
void PrintSourceLocation(InternalScopedString *buffer, const char *file,
|
||||
int line, int column) {
|
||||
CHECK(file);
|
||||
|
@ -217,17 +225,6 @@ bool LoadedModule::containsAddress(uptr address) const {
|
|||
return false;
|
||||
}
|
||||
|
||||
char *StripModuleName(const char *module) {
|
||||
if (module == 0)
|
||||
return 0;
|
||||
const char *short_module_name = internal_strrchr(module, '/');
|
||||
if (short_module_name)
|
||||
short_module_name += 1;
|
||||
else
|
||||
short_module_name = module;
|
||||
return internal_strdup(short_module_name);
|
||||
}
|
||||
|
||||
static atomic_uintptr_t g_total_mmaped;
|
||||
|
||||
void IncreaseTotalMmap(uptr size) {
|
||||
|
|
|
@ -172,6 +172,8 @@ bool IsAccessibleMemoryRange(uptr beg, uptr size);
|
|||
// Error report formatting.
|
||||
const char *StripPathPrefix(const char *filepath,
|
||||
const char *strip_file_prefix);
|
||||
// Strip the directories from the module name.
|
||||
const char *StripModuleName(const char *module);
|
||||
void PrintSourceLocation(InternalScopedString *buffer, const char *file,
|
||||
int line, int column);
|
||||
void PrintModuleAndOffset(InternalScopedString *buffer,
|
||||
|
@ -209,9 +211,6 @@ void SleepForMillis(int millis);
|
|||
u64 NanoTime();
|
||||
int Atexit(void (*function)(void));
|
||||
void SortArray(uptr *array, uptr size);
|
||||
// Strip the directories from the module name, return a new string allocated
|
||||
// with internal_strdup.
|
||||
char *StripModuleName(const char *module);
|
||||
|
||||
// Exit
|
||||
void NORETURN Abort();
|
||||
|
|
|
@ -387,7 +387,7 @@ static void CovDump() {
|
|||
CHECK_LE(diff, 0xffffffffU);
|
||||
offsets.push_back(static_cast<u32>(diff));
|
||||
}
|
||||
char *module_name = StripModuleName(module.data());
|
||||
const char *module_name = StripModuleName(module.data());
|
||||
if (cov_sandboxed) {
|
||||
if (cov_fd >= 0) {
|
||||
CovWritePacked(internal_getpid(), module_name, offsets.data(),
|
||||
|
@ -407,7 +407,6 @@ static void CovDump() {
|
|||
vb - old_vb);
|
||||
}
|
||||
}
|
||||
InternalFree(module_name);
|
||||
}
|
||||
}
|
||||
if (cov_fd >= 0)
|
||||
|
|
|
@ -80,7 +80,7 @@ void CovUpdateMapping(uptr caller_pc) {
|
|||
|
||||
text.append("%d\n", sizeof(uptr) * 8);
|
||||
for (int i = 0; i < n_modules; ++i) {
|
||||
char *module_name = StripModuleName(modules[i].full_name());
|
||||
const char *module_name = StripModuleName(modules[i].full_name());
|
||||
for (unsigned j = 0; j < modules[i].n_ranges(); ++j) {
|
||||
if (modules[i].address_range_executable(j)) {
|
||||
uptr start = modules[i].address_range_start(j);
|
||||
|
@ -91,7 +91,6 @@ void CovUpdateMapping(uptr caller_pc) {
|
|||
cached_mapping.SetModuleRange(start, end);
|
||||
}
|
||||
}
|
||||
InternalFree(module_name);
|
||||
}
|
||||
|
||||
int err;
|
||||
|
|
|
@ -115,9 +115,7 @@ void PrintStack(const ReportStack *ent) {
|
|||
if (ent->col)
|
||||
Printf(":%d", ent->col);
|
||||
if (ent->module && ent->offset) {
|
||||
char *stripped_module = StripModuleName(ent->module);
|
||||
Printf(" (%s+%p)\n", stripped_module, (void*)ent->offset);
|
||||
InternalFree(stripped_module);
|
||||
Printf(" (%s+%p)\n", StripModuleName(ent->module), (void*)ent->offset);
|
||||
} else {
|
||||
Printf(" (%p)\n", (void*)ent->pc);
|
||||
}
|
||||
|
@ -162,10 +160,8 @@ static void PrintLocation(const ReportLocation *loc) {
|
|||
bool print_stack = false;
|
||||
Printf("%s", d.Location());
|
||||
if (loc->type == ReportLocationGlobal) {
|
||||
char *stripped_module = StripModuleName(loc->module);
|
||||
Printf(" Location is global '%s' of size %zu at %p (%s+%p)\n\n",
|
||||
loc->name, loc->size, loc->addr, stripped_module, loc->offset);
|
||||
InternalFree(stripped_module);
|
||||
Printf(" Location is global '%s' of size %zu at %p (%s+%p)\n\n", loc->name,
|
||||
loc->size, loc->addr, StripModuleName(loc->module), loc->offset);
|
||||
} else if (loc->type == ReportLocationHeap) {
|
||||
char thrbuf[kThreadBufSize];
|
||||
Printf(" Location is heap block of size %zu at %p allocated by %s:\n",
|
||||
|
|
Loading…
Reference in New Issue