Skip to content

Commit bca07d6

Browse files
committed
Avoid force loading symbol files in statistics collection
This commit modifies the `DebuggerStats::ReportStatistics` implementation to avoid loading symbol files for unloaded symbols. We collect stats on debugger shutdown and without this change it can cause the debugger to hang for a long while on shutdown if they symbols were not previously loaded (e.g. `settings set target.preload-symbols false`). The implementation is done by adding an optional parameter to `Module::GetSymtab` to control if the corresponding symbol file will be loaded in the same way that can control it for `Module::GetSymbolFile`.
1 parent 11b9466 commit bca07d6

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

lldb/include/lldb/Core/Module.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,11 @@ class Module : public std::enable_shared_from_this<Module>,
608608
virtual SymbolFile *GetSymbolFile(bool can_create = true,
609609
Stream *feedback_strm = nullptr);
610610

611-
Symtab *GetSymtab();
611+
/// Get the module's symbol table
612+
///
613+
/// If the symbol table has already been loaded, this function returns it.
614+
/// Otherwise, it will only be loaded when can_create is true.
615+
Symtab *GetSymtab(bool can_create = true);
612616

613617
/// Get a reference to the UUID value contained in this object.
614618
///

lldb/source/Core/Module.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,8 +1022,8 @@ SymbolFile *Module::GetSymbolFile(bool can_create, Stream *feedback_strm) {
10221022
return m_symfile_up ? m_symfile_up->GetSymbolFile() : nullptr;
10231023
}
10241024

1025-
Symtab *Module::GetSymtab() {
1026-
if (SymbolFile *symbols = GetSymbolFile())
1025+
Symtab *Module::GetSymtab(bool can_create) {
1026+
if (SymbolFile *symbols = GetSymbolFile(can_create))
10271027
return symbols->GetSymtab();
10281028
return nullptr;
10291029
}

lldb/source/Target/Statistics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ llvm::json::Value DebuggerStats::ReportStatistics(
316316
ModuleStats module_stat;
317317
module_stat.symtab_parse_time = module->GetSymtabParseTime().get().count();
318318
module_stat.symtab_index_time = module->GetSymtabIndexTime().get().count();
319-
Symtab *symtab = module->GetSymtab();
319+
Symtab *symtab = module->GetSymtab(/*can_create=*/false);
320320
if (symtab) {
321321
module_stat.symtab_loaded_from_cache = symtab->GetWasLoadedFromCache();
322322
if (module_stat.symtab_loaded_from_cache)
@@ -325,7 +325,7 @@ llvm::json::Value DebuggerStats::ReportStatistics(
325325
if (module_stat.symtab_saved_to_cache)
326326
++symtabs_saved;
327327
}
328-
SymbolFile *sym_file = module->GetSymbolFile();
328+
SymbolFile *sym_file = module->GetSymbolFile(/*can_create=*/false);
329329
if (sym_file) {
330330
if (!summary_only) {
331331
if (sym_file->GetObjectFile() != module->GetObjectFile())
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# RUN: %clang_host -g %S/Inputs/main.c -o %t-main.exe
2+
3+
# When we enable symbol preload and dump stats there should be a non-zero
4+
# time for parsing symbol tables for the main module.
5+
# RUN: %lldb %t-main.exe \
6+
# RUN: -O "settings set plugin.jit-loader.gdb.enable off" \
7+
# RUN: -O "settings set target.preload-symbols true" \
8+
# RUN: -o "statistics dump" \
9+
# RUN: -o "q" \
10+
# RUN: | FileCheck %s -check-prefixes=CHECK,PRELOAD_TRUE
11+
12+
# Find the module stats for the main executable and make sure
13+
# we are looking at the symbol parse time for that module.
14+
# CHECK: "modules": [
15+
# CHECK: {
16+
# CHECK: "path": {{.*}}-main.exe
17+
# CHECK-NOT: }
18+
19+
# PRELOAD_TRUE: "symbolTableParseTime":
20+
# PRELOAD_TRUE-SAME: {{[1-9]+}}
21+
22+
# When we disable symbol preload and dump stats the symbol table
23+
# for main should not be parsed and have a time of 0.
24+
# RUN: %lldb %t-main.exe \
25+
# RUN: -O "settings set plugin.jit-loader.gdb.enable off" \
26+
# RUN: -O "settings set target.preload-symbols false" \
27+
# RUN: -o "statistics dump" \
28+
# RUN: -o "q" \
29+
# RUN: | FileCheck %s -check-prefixes=CHECK,PRELOAD_FALSE
30+
31+
# PRELOAD_FALSE: "symbolTableParseTime": 0,

0 commit comments

Comments
 (0)