Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions lldb/source/Commands/CommandObjectTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3946,46 +3946,46 @@ class CommandObjectTargetModulesLookup : public CommandObjectParsed {

Options *GetOptions() override { return &m_options; }

bool LookupHere(CommandInterpreter &interpreter, CommandReturnObject &result,
bool &syntax_error) {
ModuleSP LookupHere(CommandInterpreter &interpreter,
CommandReturnObject &result, bool &syntax_error) {
switch (m_options.m_type) {
case eLookupTypeAddress:
case eLookupTypeFileLine:
case eLookupTypeFunction:
case eLookupTypeFunctionOrSymbol:
case eLookupTypeSymbol:
default:
return false;
return nullptr;
case eLookupTypeType:
break;
}

StackFrameSP frame = m_exe_ctx.GetFrameSP();

if (!frame)
return false;
return nullptr;

const SymbolContext &sym_ctx(frame->GetSymbolContext(eSymbolContextModule));

if (!sym_ctx.module_sp)
return false;
return nullptr;

switch (m_options.m_type) {
default:
return false;
return nullptr;
case eLookupTypeType:
if (!m_options.m_str.empty()) {
if (LookupTypeHere(&GetTarget(), m_interpreter,
result.GetOutputStream(), *sym_ctx.module_sp,
m_options.m_str.c_str(), m_options.m_use_regex)) {
result.SetStatus(eReturnStatusSuccessFinishResult);
return true;
return sym_ctx.module_sp;
}
}
break;
}

return false;
return nullptr;
}

bool LookupInModule(CommandInterpreter &interpreter, Module *module,
Expand Down Expand Up @@ -4086,12 +4086,12 @@ class CommandObjectTargetModulesLookup : public CommandObjectParsed {
// Dump all sections for all modules images

if (command.GetArgumentCount() == 0) {
ModuleSP current_module;

// Where it is possible to look in the current symbol context first,
// try that. If this search was successful and --all was not passed,
// don't print anything else.
if (LookupHere(m_interpreter, result, syntax_error)) {
ModuleSP current_module_sp =
LookupHere(m_interpreter, result, syntax_error);
if (current_module_sp) {
result.GetOutputStream().EOL();
num_successful_lookups++;
if (!m_options.m_print_all) {
Expand All @@ -4110,7 +4110,7 @@ class CommandObjectTargetModulesLookup : public CommandObjectParsed {
}

for (ModuleSP module_sp : target_modules.ModulesNoLocking()) {
if (module_sp != current_module &&
if (module_sp != current_module_sp &&
LookupInModule(m_interpreter, module_sp.get(), result,
syntax_error)) {
result.GetOutputStream().EOL();
Expand Down
43 changes: 43 additions & 0 deletions lldb/test/Shell/Commands/command-image-lookup-current-module.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# REQUIRES: system-darwin

# RUN: split-file %s %t
# RUN: %clang_host -g -gdwarf %t/lib1.cpp -shared -o %t-lib1.dylib
# RUN: %clang_host -g -gdwarf %t/lib2.cpp -shared -o %t-lib2.dylib
# RUN: %clang_host -g -gdwarf %t/main.cpp %t-lib1.dylib %t-lib2.dylib -o %t.out
# RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \
# RUN: | FileCheck %s

#--- main.cpp

struct Foo {} f;

int main() { __builtin_debugtrap(); }

#--- lib1.cpp

struct Foo {} f1;

#--- lib2.cpp

struct Foo {} f2;

#--- commands.input

run
target modules lookup --type Foo

# CHECK: (lldb) target modules lookup --type Foo
# CHECK-NEXT: Best match found in
# CHECK-NEXT: name = "Foo"

# Confirm we only dumped the match once.
# CHECK-NOT: name = "Foo"

target modules lookup --type Foo --all

# CHECK: (lldb) target modules lookup --type Foo --all
# CHECK-NEXT: Best match found in
# CHECK-NEXT: name = "Foo"

# CHECK: 1 match found in {{.*}}lib1.dylib
# CHECK: 1 match found in {{.*}}lib2.dylib
Loading