Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9882d68
add DAP gettModuleSymbols request
eronnen Aug 9, 2025
82430e3
implement DAPGetModuleSymbolsRequestHandler
eronnen Aug 9, 2025
5496e20
adding lldb-dap.modules.showSymbols to the commandPallette
eronnen Aug 10, 2025
b5ee84e
basic HTML for symbols webview
eronnen Aug 10, 2025
9f17c74
show symbols in a simple tabulator table
eronnen Aug 11, 2025
bf6309a
split symbols webview script to a new ts directory
eronnen Aug 13, 2025
c37369f
working symbol table white default theme
eronnen Aug 14, 2025
e76bb2f
common formatter
eronnen Aug 14, 2025
738962f
restore ts files to src-ts
eronnen Aug 14, 2025
de3ee14
fit table columns to viewport
eronnen Aug 15, 2025
f16d15b
make table data restore after switching tabs
eronnen Aug 15, 2025
262875c
attempt have tabulator with vscode css variables
eronnen Aug 15, 2025
e65178e
better looking CSS with tabulator
eronnen Aug 15, 2025
ae21288
remove ellipsis if text is long
eronnen Aug 15, 2025
023c7fa
few fixes
eronnen Aug 15, 2025
bab7e01
revert
eronnen Aug 15, 2025
2e48fdb
table improvements
eronnen Aug 15, 2025
d8f17bc
add context menu show symbols for modules
eronnen Aug 15, 2025
68281f3
remove unecessary type
eronnen Aug 15, 2025
1ddd26b
format
eronnen Aug 15, 2025
c499355
move DAPTypes to a namespace
eronnen Aug 15, 2025
0e668d0
rename to ModuleSymbolsRequestHandler
eronnen Aug 15, 2025
b36db9a
revert extra dap namespace
eronnen Aug 16, 2025
de67bac
format
eronnen Aug 16, 2025
b6f6766
rename
eronnen Aug 16, 2025
7c7f477
use symbol type as enum
eronnen Aug 16, 2025
7c0ad87
identifying lldb-dap version and using it in command context to enabl…
eronnen Aug 16, 2025
6581b34
fix
eronnen Aug 16, 2025
1f168a7
add index and count to the moduleSymbols request
eronnen Aug 16, 2025
693e29c
adding simple test for the moduleSymbols request
eronnen Aug 16, 2025
f8da9f1
format
eronnen Aug 16, 2025
626ba0c
split DSX to Debug Synthetic External columns
eronnen Aug 16, 2025
c4f59e4
format
eronnen Aug 16, 2025
012076c
remove console.log
eronnen Aug 16, 2025
024b566
format
eronnen Aug 16, 2025
6fccbaa
add docs, organize and change userId -> id
eronnen Aug 18, 2025
d61715e
use capabilities event to determine SupportsModuleSymbolsRequest inst…
eronnen Aug 18, 2025
f0fc40c
using better tick element from tabulator
eronnen Aug 19, 2025
3aea6b6
Sending extra capabilities event together
eronnen Aug 19, 2025
1f3ae21
rename js
eronnen Aug 19, 2025
15fd62b
add __lldb_ prefix
eronnen Aug 19, 2025
ca40bc1
add __lldb_ prefix in test
eronnen Aug 20, 2025
300819c
export Symbol::GetTypeAsString and Symbol::GetTypeFromString
eronnen Aug 20, 2025
30601fa
fix docs
eronnen Aug 20, 2025
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
15 changes: 15 additions & 0 deletions lldb/include/lldb/API/SBSymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ class LLDB_API SBSymbol {

SymbolType GetType();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a docstring

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

/// Get the ID of this symbol, usually the original symbol table index.
///
/// \returns
/// Returns the ID of this symbol.
uint32_t GetID();

bool operator==(const lldb::SBSymbol &rhs) const;

bool operator!=(const lldb::SBSymbol &rhs) const;
Expand All @@ -99,6 +105,15 @@ class LLDB_API SBSymbol {
// other than the actual symbol table itself in the object file.
bool IsSynthetic();

/// Returns true if the symbol is a debug symbol.
bool IsDebug();

/// Get the string representation of a symbol type.
static const char *GetTypeAsString(lldb::SymbolType symbol_type);

/// Get the symbol type from a string representation.
static lldb::SymbolType GetTypeFromString(const char *str);

protected:
lldb_private::Symbol *get();

Expand Down
10 changes: 10 additions & 0 deletions lldb/include/lldb/API/SBTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,16 @@ class LLDB_API SBTarget {

lldb::SBModule FindModule(const lldb::SBFileSpec &file_spec);

/// Find a module with the given module specification.
///
/// \param[in] module_spec
/// A lldb::SBModuleSpec object that contains module specification.
///
/// \return
/// A lldb::SBModule object that represents the found module, or an
/// invalid SBModule object if no module was found.
lldb::SBModule FindModule(const lldb::SBModuleSpec &module_spec);

/// Find compile units related to *this target and passed source
/// file.
///
Expand Down
5 changes: 5 additions & 0 deletions lldb/include/lldb/Symbol/Symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "lldb/Symbol/SymbolContextScope.h"
#include "lldb/Utility/Stream.h"
#include "lldb/Utility/UserID.h"
#include "lldb/lldb-enumerations.h"
#include "lldb/lldb-private.h"
#include "llvm/Support/JSON.h"

Expand Down Expand Up @@ -301,6 +302,10 @@ class Symbol : public SymbolContextScope {

bool operator==(const Symbol &rhs) const;

static const char *GetTypeAsString(lldb::SymbolType symbol_type);

static lldb::SymbolType GetTypeFromString(const char *str);

protected:
// This is the internal guts of ResolveReExportedSymbol, it assumes
// reexport_name is not null, and that module_spec is valid. We track the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,25 @@ def request_modules(self, startModule: int, moduleCount: int):
}
)

def request_moduleSymbols(
self,
moduleId: str = "",
moduleName: str = "",
startIndex: int = 0,
count: int = 0,
):
command_dict = {
"command": "__lldb_moduleSymbols",
"type": "request",
"arguments": {
"moduleId": moduleId,
"moduleName": moduleName,
"startIndex": startIndex,
"count": count,
},
}
return self.send_recv(command_dict)

def request_stackTrace(
self, threadId=None, startFrame=None, levels=None, format=None, dump=False
):
Expand Down
28 changes: 28 additions & 0 deletions lldb/source/API/SBSymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ SymbolType SBSymbol::GetType() {
return eSymbolTypeInvalid;
}

uint32_t SBSymbol::GetID() {
LLDB_INSTRUMENT_VA(this);

if (m_opaque_ptr)
return m_opaque_ptr->GetID();
return 0;
}

bool SBSymbol::IsExternal() {
LLDB_INSTRUMENT_VA(this);

Expand All @@ -208,3 +216,23 @@ bool SBSymbol::IsSynthetic() {
return m_opaque_ptr->IsSynthetic();
return false;
}

bool SBSymbol::IsDebug() {
LLDB_INSTRUMENT_VA(this);

if (m_opaque_ptr)
return m_opaque_ptr->IsDebug();
return false;
}

const char *SBSymbol::GetTypeAsString(lldb::SymbolType symbol_type) {
LLDB_INSTRUMENT_VA(symbol_type);

return Symbol::GetTypeAsString(symbol_type);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return Symbol::GetTypeAsString(symbol_type);
LLDB_INSTRUMENT_VA(type);
return Symbol::GetTypeAsString(symbol_type);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

}

lldb::SymbolType SBSymbol::GetTypeFromString(const char *str) {
LLDB_INSTRUMENT_VA(str);

return Symbol::GetTypeFromString(str);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return Symbol::GetTypeFromString(str);
LLDB_INSTRUMENT_VA(type);
return Symbol::GetTypeFromString(str);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

}
12 changes: 12 additions & 0 deletions lldb/source/API/SBTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,18 @@ SBModule SBTarget::FindModule(const SBFileSpec &sb_file_spec) {
return sb_module;
}

SBModule SBTarget::FindModule(const SBModuleSpec &sb_module_spec) {
LLDB_INSTRUMENT_VA(this, sb_module_spec);

SBModule sb_module;
if (TargetSP target_sp = GetSP(); target_sp && sb_module_spec.IsValid()) {
// The module list is thread safe, no need to lock.
sb_module.SetSP(
target_sp->GetImages().FindFirstModule(*sb_module_spec.m_opaque_up));
}
return sb_module;
}

SBSymbolContextList SBTarget::FindCompileUnits(const SBFileSpec &sb_file_spec) {
LLDB_INSTRUMENT_VA(this, sb_file_spec);

Expand Down
144 changes: 76 additions & 68 deletions lldb/source/Symbol/Symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,45 +392,8 @@ bool Symbol::Compare(ConstString name, SymbolType type) const {
return false;
}

#define ENUM_TO_CSTRING(x) \
case eSymbolType##x: \
return #x;

const char *Symbol::GetTypeAsString() const {
switch (m_type) {
ENUM_TO_CSTRING(Invalid);
ENUM_TO_CSTRING(Absolute);
ENUM_TO_CSTRING(Code);
ENUM_TO_CSTRING(Resolver);
ENUM_TO_CSTRING(Data);
ENUM_TO_CSTRING(Trampoline);
ENUM_TO_CSTRING(Runtime);
ENUM_TO_CSTRING(Exception);
ENUM_TO_CSTRING(SourceFile);
ENUM_TO_CSTRING(HeaderFile);
ENUM_TO_CSTRING(ObjectFile);
ENUM_TO_CSTRING(CommonBlock);
ENUM_TO_CSTRING(Block);
ENUM_TO_CSTRING(Local);
ENUM_TO_CSTRING(Param);
ENUM_TO_CSTRING(Variable);
ENUM_TO_CSTRING(VariableType);
ENUM_TO_CSTRING(LineEntry);
ENUM_TO_CSTRING(LineHeader);
ENUM_TO_CSTRING(ScopeBegin);
ENUM_TO_CSTRING(ScopeEnd);
ENUM_TO_CSTRING(Additional);
ENUM_TO_CSTRING(Compiler);
ENUM_TO_CSTRING(Instrumentation);
ENUM_TO_CSTRING(Undefined);
ENUM_TO_CSTRING(ObjCClass);
ENUM_TO_CSTRING(ObjCMetaClass);
ENUM_TO_CSTRING(ObjCIVar);
ENUM_TO_CSTRING(ReExported);
default:
break;
}
return "<unknown SymbolType>";
return GetTypeAsString(static_cast<lldb::SymbolType>(m_type));
}

void Symbol::CalculateSymbolContext(SymbolContext *sc) {
Expand Down Expand Up @@ -774,6 +737,79 @@ bool Symbol::operator==(const Symbol &rhs) const {
return true;
}

#define ENUM_TO_CSTRING(x) \
case eSymbolType##x: \
return #x;

const char *Symbol::GetTypeAsString(lldb::SymbolType symbol_type) {
switch (symbol_type) {
ENUM_TO_CSTRING(Invalid);
ENUM_TO_CSTRING(Absolute);
ENUM_TO_CSTRING(Code);
ENUM_TO_CSTRING(Resolver);
ENUM_TO_CSTRING(Data);
ENUM_TO_CSTRING(Trampoline);
ENUM_TO_CSTRING(Runtime);
ENUM_TO_CSTRING(Exception);
ENUM_TO_CSTRING(SourceFile);
ENUM_TO_CSTRING(HeaderFile);
ENUM_TO_CSTRING(ObjectFile);
ENUM_TO_CSTRING(CommonBlock);
ENUM_TO_CSTRING(Block);
ENUM_TO_CSTRING(Local);
ENUM_TO_CSTRING(Param);
ENUM_TO_CSTRING(Variable);
ENUM_TO_CSTRING(VariableType);
ENUM_TO_CSTRING(LineEntry);
ENUM_TO_CSTRING(LineHeader);
ENUM_TO_CSTRING(ScopeBegin);
ENUM_TO_CSTRING(ScopeEnd);
ENUM_TO_CSTRING(Additional);
ENUM_TO_CSTRING(Compiler);
ENUM_TO_CSTRING(Instrumentation);
ENUM_TO_CSTRING(Undefined);
ENUM_TO_CSTRING(ObjCClass);
ENUM_TO_CSTRING(ObjCMetaClass);
ENUM_TO_CSTRING(ObjCIVar);
ENUM_TO_CSTRING(ReExported);
}
return "<unknown SymbolType>";
}

lldb::SymbolType Symbol::GetTypeFromString(const char *str) {
std::string str_lower = llvm::StringRef(str).lower();
return llvm::StringSwitch<lldb::SymbolType>(str_lower)
.Case("absolute", eSymbolTypeAbsolute)
.Case("code", eSymbolTypeCode)
.Case("resolver", eSymbolTypeResolver)
.Case("data", eSymbolTypeData)
.Case("trampoline", eSymbolTypeTrampoline)
.Case("runtime", eSymbolTypeRuntime)
.Case("exception", eSymbolTypeException)
.Case("sourcefile", eSymbolTypeSourceFile)
.Case("headerfile", eSymbolTypeHeaderFile)
.Case("objectfile", eSymbolTypeObjectFile)
.Case("commonblock", eSymbolTypeCommonBlock)
.Case("block", eSymbolTypeBlock)
.Case("local", eSymbolTypeLocal)
.Case("param", eSymbolTypeParam)
.Case("variable", eSymbolTypeVariable)
.Case("variableType", eSymbolTypeVariableType)
.Case("lineentry", eSymbolTypeLineEntry)
.Case("lineheader", eSymbolTypeLineHeader)
.Case("scopebegin", eSymbolTypeScopeBegin)
.Case("scopeend", eSymbolTypeScopeEnd)
.Case("additional,", eSymbolTypeAdditional)
.Case("compiler", eSymbolTypeCompiler)
.Case("instrumentation", eSymbolTypeInstrumentation)
.Case("undefined", eSymbolTypeUndefined)
.Case("objcclass", eSymbolTypeObjCClass)
.Case("objcmetaclass", eSymbolTypeObjCMetaClass)
.Case("objcivar", eSymbolTypeObjCIVar)
.Case("reexported", eSymbolTypeReExported)
.Default(eSymbolTypeInvalid);
}

namespace llvm {
namespace json {

Expand Down Expand Up @@ -804,36 +840,8 @@ bool fromJSON(const llvm::json::Value &value, lldb_private::JSONSymbol &symbol,
bool fromJSON(const llvm::json::Value &value, lldb::SymbolType &type,
llvm::json::Path path) {
if (auto str = value.getAsString()) {
type = llvm::StringSwitch<lldb::SymbolType>(*str)
.Case("absolute", eSymbolTypeAbsolute)
.Case("code", eSymbolTypeCode)
.Case("resolver", eSymbolTypeResolver)
.Case("data", eSymbolTypeData)
.Case("trampoline", eSymbolTypeTrampoline)
.Case("runtime", eSymbolTypeRuntime)
.Case("exception", eSymbolTypeException)
.Case("sourcefile", eSymbolTypeSourceFile)
.Case("headerfile", eSymbolTypeHeaderFile)
.Case("objectfile", eSymbolTypeObjectFile)
.Case("commonblock", eSymbolTypeCommonBlock)
.Case("block", eSymbolTypeBlock)
.Case("local", eSymbolTypeLocal)
.Case("param", eSymbolTypeParam)
.Case("variable", eSymbolTypeVariable)
.Case("variableType", eSymbolTypeVariableType)
.Case("lineentry", eSymbolTypeLineEntry)
.Case("lineheader", eSymbolTypeLineHeader)
.Case("scopebegin", eSymbolTypeScopeBegin)
.Case("scopeend", eSymbolTypeScopeEnd)
.Case("additional,", eSymbolTypeAdditional)
.Case("compiler", eSymbolTypeCompiler)
.Case("instrumentation", eSymbolTypeInstrumentation)
.Case("undefined", eSymbolTypeUndefined)
.Case("objcclass", eSymbolTypeObjCClass)
.Case("objcmetaClass", eSymbolTypeObjCMetaClass)
.Case("objcivar", eSymbolTypeObjCIVar)
.Case("reexporte", eSymbolTypeReExported)
.Default(eSymbolTypeInvalid);
llvm::StringRef str_ref = str.value_or("");
type = Symbol::GetTypeFromString(str_ref.data());

if (type == eSymbolTypeInvalid) {
path.report("invalid symbol type");
Expand Down
3 changes: 3 additions & 0 deletions lldb/test/API/tools/lldb-dap/moduleSymbols/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
C_SOURCES := main.c

include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
Test lldb-dap moduleSymbols request
"""

import lldbdap_testcase


class TestDAP_moduleSymbols(lldbdap_testcase.DAPTestCaseBase):
def test_moduleSymbols(self):
"""
Test that the moduleSymbols request returns correct symbols from the module.
"""
program = self.getBuildArtifact("a.out")
self.build_and_launch(program)

symbol_names = []
i = 0
while True:
next_symbol = self.dap_server.request_moduleSymbols(
moduleName="a.out", startIndex=i, count=1
)
self.assertIn("symbols", next_symbol["body"])
result_symbols = next_symbol["body"]["symbols"]
self.assertLessEqual(len(result_symbols), 1)
if len(result_symbols) == 0:
break

self.assertIn("name", result_symbols[0])
symbol_names.append(result_symbols[0]["name"])
i += 1
if i >= 1000:
break

self.assertGreater(len(symbol_names), 0)
self.assertIn("main", symbol_names)
self.assertIn("func1", symbol_names)
self.assertIn("func2", symbol_names)
9 changes: 9 additions & 0 deletions lldb/test/API/tools/lldb-dap/moduleSymbols/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
int func1() { return 42; }

int func2() { return 84; }

int main() {
func1();
func2();
return 0;
}
1 change: 1 addition & 0 deletions lldb/tools/lldb-dap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ add_lldb_library(lldbDAP
Handler/LaunchRequestHandler.cpp
Handler/LocationsRequestHandler.cpp
Handler/ModulesRequestHandler.cpp
Handler/ModuleSymbolsRequestHandler.cpp
Handler/NextRequestHandler.cpp
Handler/PauseRequestHandler.cpp
Handler/ReadMemoryRequestHandler.cpp
Expand Down
Loading
Loading