[Lldb-commits] [lldb] [lldb] Find the default source file's main by base name (PR #207043)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Wed Jul 1 11:00:40 PDT 2026
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/207043
SourceManager::GetDefaultFileAndLine locates the executable's main to pick a default source file, used for input like "break set -l N" with no file specified. It searched for main by full name, but a function's linkage name can differ from its source name, in which case a full-name search for "main" does not find it and no default file is chosen.
For example, wasi-libc renames main to __main_argc_argv, so on WebAssembly the debug function for main was never matched and "break set -l N" failed with "no default file available".
Search by base name instead. The base name is "main" regardless of the linkage name, and where the two coincide the behavior is unchanged.
>From cebd971d1866bea6857e2a278b23f95ed8b20b6a Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jonas at devlieghere.com>
Date: Wed, 1 Jul 2026 10:59:36 -0700
Subject: [PATCH] [lldb] Find the default source file's main by base name
SourceManager::GetDefaultFileAndLine locates the executable's main to
pick a default source file, used for input like "break set -l N" with no
file specified. It searched for main by full name, but a function's
linkage name can differ from its source name, in which case a full-name
search for "main" does not find it and no default file is chosen.
For example, wasi-libc renames main to __main_argc_argv, so on
WebAssembly the debug function for main was never matched and "break set
-l N" failed with "no default file available".
Search by base name instead. The base name is "main" regardless of the
linkage name, and where the two coincide the behavior is unchanged.
---
lldb/source/Core/SourceManager.cpp | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lldb/source/Core/SourceManager.cpp b/lldb/source/Core/SourceManager.cpp
index d3e1bb5d332f0..af73a2c571c0f 100644
--- a/lldb/source/Core/SourceManager.cpp
+++ b/lldb/source/Core/SourceManager.cpp
@@ -429,8 +429,11 @@ SourceManager::GetDefaultFileAndLine() {
function_options.include_symbols =
false; // Force it to be a debug symbol.
function_options.include_inlines = true;
+ // The linkage name can differ from the source name, so match on the
+ // base name to find the function regardless of how it was mangled or
+ // renamed.
executable_ptr->FindFunctions(main_name, CompilerDeclContext(),
- lldb::eFunctionNameTypeFull,
+ lldb::eFunctionNameTypeBase,
function_options, sc_list);
for (const SymbolContext &sc : sc_list) {
if (sc.function) {
More information about the lldb-commits
mailing list