Skip to content

Commit f87c722

Browse files
committed
Update display name logic
1 parent ac402a4 commit f87c722

8 files changed

+81
-6
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_aix.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,22 @@ u64 MonotonicNanoTime() {
492492
return (u64)ts.tv_sec * (1000ULL * 1000 * 1000) + ts.tv_nsec;
493493
}
494494

495+
void DumpProcessMap() {
496+
MemoryMappingLayout proc_maps(/*cache_enabled*/true);
497+
const sptr kBufSize = 4095;
498+
char *filename = (char*)MmapOrDie(kBufSize, __func__);
499+
char *displayname = (char*)MmapOrDie(kBufSize, __func__);
500+
MemoryMappedSegment segment(filename, kBufSize, displayname, kBufSize);
501+
Report("Process memory map follows:\n");
502+
while (proc_maps.Next(&segment)) {
503+
Printf("\t%p-%p\t%s\n", (void *)segment.start, (void *)segment.end,
504+
segment.displayname);
505+
}
506+
Report("End of process memory map.\n");
507+
UnmapOrDie(filename, kBufSize);
508+
UnmapOrDie(displayname, kBufSize);
509+
}
510+
495511
// FIXME implement on this platform.
496512
void GetMemoryProfile(fill_profile_f cb, uptr *stats) {}
497513

compiler-rt/lib/sanitizer_common/sanitizer_common.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ void LoadedModule::set(const char *module_name, uptr base_address,
171171
instrumented_ = instrumented;
172172
}
173173

174+
void LoadedModule::setDisplayName(const char *display_name) {
175+
display_name_ = internal_strdup(display_name);
176+
}
177+
174178
void LoadedModule::setUuid(const char *uuid, uptr size) {
175179
if (size > kModuleUUIDSize)
176180
size = kModuleUUIDSize;
@@ -180,9 +184,11 @@ void LoadedModule::setUuid(const char *uuid, uptr size) {
180184

181185
void LoadedModule::clear() {
182186
InternalFree(full_name_);
187+
InternalFree(display_name_);
183188
base_address_ = 0;
184189
max_address_ = 0;
185190
full_name_ = nullptr;
191+
display_name_ = nullptr;
186192
arch_ = kModuleArchUnknown;
187193
internal_memset(uuid_, 0, kModuleUUIDSize);
188194
instrumented_ = false;

compiler-rt/lib/sanitizer_common/sanitizer_common.h

+4
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@ class LoadedModule {
831831
public:
832832
LoadedModule()
833833
: full_name_(nullptr),
834+
display_name_(nullptr),
834835
base_address_(0),
835836
max_address_(0),
836837
arch_(kModuleArchUnknown),
@@ -842,13 +843,15 @@ class LoadedModule {
842843
void set(const char *module_name, uptr base_address);
843844
void set(const char *module_name, uptr base_address, ModuleArch arch,
844845
u8 uuid[kModuleUUIDSize], bool instrumented);
846+
void setDisplayName(const char *display_name);
845847
void setUuid(const char *uuid, uptr size);
846848
void clear();
847849
void addAddressRange(uptr beg, uptr end, bool executable, bool writable,
848850
const char *name = nullptr);
849851
bool containsAddress(uptr address) const;
850852

851853
const char *full_name() const { return full_name_; }
854+
const char *display_name() const {return display_name_;}
852855
uptr base_address() const { return base_address_; }
853856
uptr max_address() const { return max_address_; }
854857
ModuleArch arch() const { return arch_; }
@@ -879,6 +882,7 @@ class LoadedModule {
879882

880883
private:
881884
char *full_name_; // Owned.
885+
char *display_name_;
882886
uptr base_address_;
883887
uptr max_address_;
884888
ModuleArch arch_;

compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -416,18 +416,19 @@ bool MmapFixedSuperNoReserve(uptr fixed_addr, uptr size, const char *name) {
416416
}
417417

418418
uptr ReservedAddressRange::Init(uptr size, const char *name, uptr fixed_addr) {
419+
# if !SANITIZER_AIX
420+
base_ = fixed_addr ? MmapFixedNoAccess(fixed_addr, size, name)
421+
: MmapNoAccess(size);
422+
# else
419423
// AIX can not mmap on a mmaped memory, so init it as read/write so we won't
420424
// mmap on this memory again.
421-
# if SANITIZER_AIX
422425
if (fixed_addr) {
423426
MmapFixed(fixed_addr, size, MAP_PRIVATE | MAP_FIXED | MAP_ANON, name);
424427
base_ = (void *)fixed_addr;
425-
} else
428+
} else {
426429
base_ = (void *)internal_mmap(nullptr, size, PROT_READ | PROT_WRITE,
427430
MAP_PRIVATE | MAP_ANON, -1, 0);
428-
# else
429-
base_ = fixed_addr ? MmapFixedNoAccess(fixed_addr, size, name)
430-
: MmapNoAccess(size);
431+
}
431432
# endif
432433
size_ = size;
433434
name_ = name;

compiler-rt/lib/sanitizer_common/sanitizer_procmaps_aix.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ bool MemoryMappingLayout::Next(MemoryMappedSegment *segment) {
106106
constexpr unsigned BUFFER_SIZE = 128;
107107
char objPath[BUFFER_SIZE] = {};
108108
// Use path /proc/<pid>/object/<object_id> to pass to the symbolizer.
109+
// TODO: Append the archive member name if it exists.
109110
internal_snprintf(objPath, BUFFER_SIZE, "/proc/%d/object/%s",
110111
internal_getpid(), mapIter->pr_mapname);
111112
len = Min((uptr)internal_strlen(objPath), segment->filename_size - 1);
@@ -114,6 +115,7 @@ bool MemoryMappingLayout::Next(MemoryMappedSegment *segment) {
114115

115116
// We don't have the full path to user libraries, so we use what we have
116117
// available as the display name.
118+
// TODO: Append the archive member name if it exists.
117119
const char *displayPath = data_.proc_self_maps.data + mapIter->pr_pathoff;
118120
len =
119121
Min((uptr)internal_strlen(displayPath), segment->displayname_size - 1);
@@ -133,6 +135,38 @@ bool MemoryMappingLayout::Next(MemoryMappedSegment *segment) {
133135
return true;
134136
}
135137

138+
void MemoryMappingLayout::DumpListOfModules(
139+
InternalMmapVectorNoCtor<LoadedModule> *modules) {
140+
Reset();
141+
InternalMmapVector<char> module_name(kMaxPathLength);
142+
InternalMmapVector<char> module_displayname(kMaxPathLength);
143+
MemoryMappedSegment segment(module_name.data(), module_name.size(),
144+
module_displayname.data(),
145+
module_displayname.size());
146+
for (uptr i = 0; Next(&segment); i++) {
147+
const char *cur_name = segment.filename;
148+
if (cur_name[0] == '\0')
149+
continue;
150+
// Don't subtract 'cur_beg' from the first entry:
151+
// * If a binary is compiled w/o -pie, then the first entry in
152+
// process maps is likely the binary itself (all dynamic libs
153+
// are mapped higher in address space). For such a binary,
154+
// instruction offset in binary coincides with the actual
155+
// instruction address in virtual memory (as code section
156+
// is mapped to a fixed memory range).
157+
// * If a binary is compiled with -pie, all the modules are
158+
// mapped high at address space (in particular, higher than
159+
// shadow memory of the tool), so the module can't be the
160+
// first entry.
161+
uptr base_address = (i ? segment.start : 0) - segment.offset;
162+
LoadedModule cur_module;
163+
cur_module.set(cur_name, base_address);
164+
cur_module.setDisplayName(segment.displayname);
165+
segment.AddAddressRanges(&cur_module);
166+
modules->push_back(cur_module);
167+
}
168+
}
169+
136170
} // namespace __sanitizer
137171

138172
#endif // SANITIZER_AIX

compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,13 @@ void FormattedStackTracePrinter::RenderFrame(InternalScopedString *buffer,
242242
RenderSourceLocation(buffer, info->file, info->line, info->column,
243243
vs_style, strip_path_prefix);
244244
} else if (info->module) {
245+
#if SANITIZER_AIX
246+
RenderModuleLocation(buffer, info->module_display, info->module_offset,
247+
info->module_arch, strip_path_prefix);
248+
#else
245249
RenderModuleLocation(buffer, info->module, info->module_offset,
246250
info->module_arch, strip_path_prefix);
247-
251+
#endif
248252
#if !SANITIZER_APPLE
249253
MaybeBuildIdToBuffer(*info, /*PrefixSpace=*/true, buffer);
250254
#endif
@@ -258,8 +262,13 @@ void FormattedStackTracePrinter::RenderFrame(InternalScopedString *buffer,
258262
// There PCs are not meaningful.
259263
} else if (info->module) {
260264
// Always strip the module name for %M.
265+
#if SANITIZER_AIX
266+
RenderModuleLocation(buffer, StripModuleName(info->module_display),
267+
info->module_offset, info->module_arch, "");
268+
#else
261269
RenderModuleLocation(buffer, StripModuleName(info->module),
262270
info->module_offset, info->module_arch, "");
271+
#endif
263272
#if !SANITIZER_APPLE
264273
MaybeBuildIdToBuffer(*info, /*PrefixSpace=*/true, buffer);
265274
#endif

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ AddressInfo::AddressInfo() {
2929

3030
void AddressInfo::Clear() {
3131
InternalFree(module);
32+
InternalFree(module_display);
3233
InternalFree(function);
3334
InternalFree(file);
3435
internal_memset(this, 0, sizeof(AddressInfo));
@@ -46,6 +47,9 @@ void AddressInfo::FillModuleInfo(const char *mod_name, uptr mod_offset,
4647

4748
void AddressInfo::FillModuleInfo(const LoadedModule &mod) {
4849
module = internal_strdup(mod.full_name());
50+
#if SANITIZER_AIX
51+
module_display = internal_strdup(mod.display_name());
52+
#endif
4953
module_offset = address - mod.base_address();
5054
module_arch = mod.arch();
5155
if (mod.uuid_size())

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.h

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct AddressInfo {
3030
uptr address;
3131

3232
char *module;
33+
char *module_display;
3334
uptr module_offset;
3435
ModuleArch module_arch;
3536
u8 uuid[kModuleUUIDSize];

0 commit comments

Comments
 (0)