Skip to content

Commit d96baa5

Browse files
committed
libdrgn: always create all modules in load_debug_info()
For the Linux kernel at least, it's important to have modules populated even if there is no debuginfo available, because the modules are necessary to load the built-in ORC data for unwinding. The break statement here intentionally prevents exhausting the module iterator, so that the Linux kernel modules don't get created. It doesn't impact functionality afterwards: only modules that we want to find debug info for are added to the module vector. So as far as I can see, this is only a performance optimization. The documentation for load_debug_info() only states "Try to load all debugging information for all loaded modules", which doesn't really specify whether the drgn Modules are actually created. By dropping this break statement, we may slightly increase runtime for the --main-symbols case, but we also improve correctness for those same cases, by ensuring that stack tracing (via ORC) can work without DWARF debug info. Closes #505 Signed-off-by: Stephen Brennan <[email protected]>
1 parent 578cbd2 commit d96baa5

File tree

2 files changed

+24
-35
lines changed

2 files changed

+24
-35
lines changed

libdrgn/debug_info.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5362,17 +5362,6 @@ drgn_program_load_debug_info(struct drgn_program *prog, const char **paths,
53625362
&& drgn_module_kind(module) == DRGN_MODULE_MAIN))
53635363
&& !drgn_module_vector_append(&modules, &module))
53645364
return &drgn_enomem;
5365-
5366-
// If we are only trying files for the main module (i.e., if
5367-
// we're not loading all default debug info and any provided
5368-
// files were all for the main module), then we only want to
5369-
// create the main module.
5370-
if (!load_default
5371-
&& drgn_module_kind(module) == DRGN_MODULE_MAIN
5372-
&& state.unmatched_provided == 0) {
5373-
err = NULL;
5374-
break;
5375-
}
53765365
}
53775366
if (err)
53785367
return err;

tests/test_debug_info.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -971,8 +971,8 @@ def test_only_main_path(self):
971971

972972
self.prog.load_debug_info([crashme_path])
973973

974-
# Only the main module should be created.
975-
self.assertEqual(list(self.prog.modules()), [self.prog.main_module()])
974+
# The main module should be created.
975+
self.assertIn(self.prog.main_module(), list(self.prog.modules()))
976976
# The provided path should be used for the main module.
977977
self.assertEqual(
978978
self.prog.main_module().loaded_file_path,
@@ -1027,8 +1027,8 @@ def test_main_by_path(self):
10271027

10281028
self.prog.load_debug_info([crashme_path], main=True)
10291029

1030-
# Only the main module should be created.
1031-
self.assertEqual(list(self.prog.modules()), [self.prog.main_module()])
1030+
# The main module should be created.
1031+
self.assertIn(self.prog.main_module(), list(self.prog.modules()))
10321032
# The provided path should be used for the main module.
10331033
self.assertEqual(
10341034
self.prog.main_module().loaded_file_path,
@@ -1053,8 +1053,8 @@ def finder(modules):
10531053

10541054
self.prog.load_debug_info(main=True)
10551055

1056-
# Only the main module should be created.
1057-
self.assertEqual(list(self.prog.modules()), [self.prog.main_module()])
1056+
# The main module should be created.
1057+
self.assertIn(self.prog.main_module(), list(self.prog.modules()))
10581058
# The finder should be called and set the file for the main module.
10591059
self.assertEqual(
10601060
self.prog.main_module().loaded_file_path,
@@ -1168,8 +1168,8 @@ def test_main_gnu_debugaltlink_by_path(self):
11681168

11691169
self.prog.load_debug_info([crashme_dwz_path, crashme_alt_path], main=True)
11701170

1171-
# Only the main module should be created.
1172-
self.assertEqual(list(self.prog.modules()), [self.prog.main_module()])
1171+
# The main module should be created.
1172+
self.assertIn(self.prog.main_module(), list(self.prog.modules()))
11731173
# The provided paths should be used for the main module.
11741174
self.assertEqual(
11751175
self.prog.main_module().loaded_file_path,
@@ -1200,8 +1200,8 @@ def finder(modules):
12001200

12011201
self.prog.load_debug_info(main=True)
12021202

1203-
# Only the main module should be created.
1204-
self.assertEqual(list(self.prog.modules()), [self.prog.main_module()])
1203+
# The main module should be created.
1204+
self.assertIn(self.prog.main_module(), list(self.prog.modules()))
12051205
# The finder should be called and set the files for the main module.
12061206
self.assertEqual(
12071207
self.prog.main_module().loaded_file_path,
@@ -1236,8 +1236,8 @@ def finder(modules):
12361236
main=True,
12371237
)
12381238

1239-
# Only the main module should be created.
1240-
self.assertEqual(list(self.prog.modules()), [self.prog.main_module()])
1239+
# The main module should be created.
1240+
self.assertIn(self.prog.main_module(), list(self.prog.modules()))
12411241
# The provided path should be used for the loaded file.
12421242
self.assertEqual(
12431243
self.prog.main_module().loaded_file_path,
@@ -1275,8 +1275,8 @@ def finder(modules):
12751275

12761276
self.assertRaises(MissingDebugInfoError, self.prog.load_debug_info, main=True)
12771277

1278-
# Only the main module should be created.
1279-
self.assertEqual(list(self.prog.modules()), [self.prog.main_module()])
1278+
# The main module should be created.
1279+
self.assertIn(self.prog.main_module(), list(self.prog.modules()))
12801280
# The finder should be called and set the loaded file for the main
12811281
# module but fail to find the supplementary file.
12821282
self.assertEqual(
@@ -1313,8 +1313,8 @@ def finder(modules):
13131313

13141314
self.prog.load_debug_info([crashme_dwz_path], main=True)
13151315

1316-
# Only the main module should be created.
1317-
self.assertEqual(list(self.prog.modules()), [self.prog.main_module()])
1316+
# The main module should be created.
1317+
self.assertIn(self.prog.main_module(), list(self.prog.modules()))
13181318
# The provided path should be used for the main module.
13191319
self.assertEqual(
13201320
self.prog.main_module().loaded_file_path,
@@ -1381,8 +1381,8 @@ def test_main_wants_gnu_debugaltlink_by_path(self):
13811381

13821382
self.prog.load_debug_info([crashme_alt_path], main=True)
13831383

1384-
# Only the main module should be created.
1385-
self.assertEqual(list(self.prog.modules()), [self.prog.main_module()])
1384+
# The main module should be created.
1385+
self.assertIn(self.prog.main_module(), list(self.prog.modules()))
13861386
# The provided path should be used for the supplementary file.
13871387
self.assertEqual(
13881388
self.prog.main_module().supplementary_debug_file_path,
@@ -1420,8 +1420,8 @@ def finder(modules):
14201420

14211421
self.prog.load_debug_info(main=True)
14221422

1423-
# Only the main module should be created.
1424-
self.assertEqual(list(self.prog.modules()), [self.prog.main_module()])
1423+
# The main module should be created.
1424+
self.assertIn(self.prog.main_module(), list(self.prog.modules()))
14251425
# The finder should be called and set the supplementary file for the
14261426
# main module.
14271427
self.assertEqual(
@@ -1448,8 +1448,8 @@ def test_main_wants_gnu_debugaltlink_not_found(self):
14481448

14491449
self.assertRaises(MissingDebugInfoError, self.prog.load_debug_info, main=True)
14501450

1451-
# Only the main module should be created.
1452-
self.assertEqual(list(self.prog.modules()), [self.prog.main_module()])
1451+
# The main module should be created.
1452+
self.assertIn(self.prog.main_module(), list(self.prog.modules()))
14531453
# The finder should be called and fail to find the supplementary file
14541454
# for the main module, but the supplementary file should still be
14551455
# wanted.
@@ -1570,8 +1570,8 @@ def finder(modules):
15701570

15711571
self.prog.load_debug_info(main=True)
15721572

1573-
# Only the main module should be created.
1574-
self.assertEqual(list(self.prog.modules()), [self.prog.main_module()])
1573+
# The main module should be created.
1574+
self.assertIn(self.prog.main_module(), list(self.prog.modules()))
15751575
# The finder should be called and set the files, address range, and
15761576
# build ID for the main module.
15771577
self.assertEqual(

0 commit comments

Comments
 (0)