kpdev42 created this revision.
kpdev42 added reviewers: clayborg, davide, k8stone, DavidSpickett.
kpdev42 added a project: LLDB.
Herald added subscribers: Enna1, JDevlieghere, mgorny.
Herald added a project: All.
kpdev42 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: lldb-commits, Sanitizers, sstefan1.
Herald added a project: Sanitizers.
Patch enables handing of DWARFv5 DW_MACRO_define_strx and DW_MACRO_undef_strx
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D130062
Files:
compiler-rt/lib/fuzzer/CMakeLists.txt
lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.h
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
lldb/test/API/lang/c/macro/Makefile
lldb/test/API/lang/c/macro/TestMacro.py
lldb/test/API/lang/c/macro/main.c
Index: lldb/test/API/lang/c/macro/main.c
===================================================================
--- /dev/null
+++ lldb/test/API/lang/c/macro/main.c
@@ -0,0 +1,7 @@
+#define DM 10
+#define DF(x) (42 + (x))
+
+int main (int argc, char const *argv[])
+{
+ return 0; //// Set break point at this line.
+}
Index: lldb/test/API/lang/c/macro/TestMacro.py
===================================================================
--- /dev/null
+++ lldb/test/API/lang/c/macro/TestMacro.py
@@ -0,0 +1,31 @@
+"""Tests lldb macro evaluation."""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class MacroTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line number to break inside main().
+ self.line = line_number('main.c', '// Set break point at this line.')
+
+ def test(self):
+ self.build()
+ exe = self.getBuildArtifact("a.out")
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+ # Break inside the main.
+ lldbutil.run_break_set_by_file_and_line(
+ self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
+
+ self.runCmd("run", RUN_SUCCEEDED)
+ self.expect("expr DM + DF(10)", VARIABLES_DISPLAYED_CORRECTLY,
+ substrs=['int', '62'])
+
Index: lldb/test/API/lang/c/macro/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/lang/c/macro/Makefile
@@ -0,0 +1,4 @@
+C_SOURCES := main.c
+CFLAGS_EXTRAS := -fdebug-macro
+
+include Makefile.rules
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -55,6 +55,8 @@
class SymbolFileDWARFDwo;
class SymbolFileDWARFDwp;
+struct DWARFStrOffsetsInfo;
+
#define DIE_IS_BEING_PARSED ((lldb_private::Type *)1)
class SymbolFileDWARF : public lldb_private::SymbolFileCommon,
@@ -244,7 +246,9 @@
bool Supports_DW_AT_APPLE_objc_complete_type(DWARFUnit *cu);
- lldb_private::DebugMacrosSP ParseDebugMacros(lldb::offset_t *offset);
+ lldb_private::DebugMacrosSP
+ ParseDebugMacros(lldb::offset_t *offset,
+ const DWARFStrOffsetsInfo &str_offsets_info);
static DWARFDIE GetParentSymbolContextDIE(const DWARFDIE &die);
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1174,7 +1174,8 @@
}
lldb_private::DebugMacrosSP
-SymbolFileDWARF::ParseDebugMacros(lldb::offset_t *offset) {
+SymbolFileDWARF::ParseDebugMacros(lldb::offset_t *offset,
+ const DWARFStrOffsetsInfo &str_offsets_info) {
auto iter = m_debug_macros_map.find(*offset);
if (iter != m_debug_macros_map.end())
return iter->second;
@@ -1190,8 +1191,8 @@
const DWARFDebugMacroHeader &header =
DWARFDebugMacroHeader::ParseHeader(debug_macro_data, offset);
DWARFDebugMacroEntry::ReadMacroEntries(
- debug_macro_data, m_context.getOrLoadStrData(), header.OffsetIs64Bit(),
- offset, this, debug_macros_sp);
+ debug_macro_data, m_context.getOrLoadStrData(), str_offsets_info,
+ header.OffsetIs64Bit(), offset, this, debug_macros_sp);
return debug_macros_sp;
}
@@ -1199,7 +1200,7 @@
bool SymbolFileDWARF::ParseDebugMacros(CompileUnit &comp_unit) {
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
- DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
+ DWARFUnit *dwarf_cu = &GetDWARFCompileUnit(&comp_unit)->GetNonSkeletonUnit();
if (dwarf_cu == nullptr)
return false;
@@ -1215,8 +1216,16 @@
if (sect_offset == DW_INVALID_OFFSET)
return false;
- comp_unit.SetDebugMacros(ParseDebugMacros(§_offset));
+ DWARFStrOffsetsInfo str_offsets_info = {};
+ str_offsets_info.cu_offset = dwarf_cu->GetStrOffsetsBase();
+ SymbolFileDWARF &symfile = dwarf_cu->GetSymbolFileDWARF();
+
+ if (str_offsets_info.IsValid())
+ str_offsets_info.data =
+ &symfile.GetDWARFContext().getOrLoadStrOffsetsData();
+ comp_unit.SetDebugMacros(
+ symfile.ParseDebugMacros(§_offset, str_offsets_info));
return true;
}
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.h
@@ -24,6 +24,14 @@
class SymbolFileDWARF;
+struct DWARFStrOffsetsInfo {
+ lldb::offset_t cu_offset;
+ const lldb_private::DWARFDataExtractor *data;
+
+ bool IsValid() const { return cu_offset && cu_offset != DW_INVALID_OFFSET; }
+ uint64_t GetOffset(uint64_t index) const;
+};
+
class DWARFDebugMacroHeader {
public:
enum HeaderFlagMask {
@@ -53,6 +61,7 @@
static void
ReadMacroEntries(const lldb_private::DWARFDataExtractor &debug_macro_data,
const lldb_private::DWARFDataExtractor &debug_str_data,
+ const DWARFStrOffsetsInfo &str_offsets_info,
const bool offset_is_64_bit, lldb::offset_t *sect_offset,
SymbolFileDWARF *sym_file_dwarf,
lldb_private::DebugMacrosSP &debug_macros_sp);
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.cpp
@@ -16,6 +16,13 @@
using namespace lldb_private;
using namespace lldb_private::dwarf;
+uint64_t DWARFStrOffsetsInfo::GetOffset(uint64_t index) const {
+ assert(IsValid());
+ // LLDB doesn't support DWARF64, so we always have item size of 4.
+ uint64_t offset = cu_offset + 4 * index;
+ return data->GetU32(&offset);
+}
+
DWARFDebugMacroHeader
DWARFDebugMacroHeader::ParseHeader(const DWARFDataExtractor &debug_macro_data,
lldb::offset_t *offset) {
@@ -59,7 +66,8 @@
void DWARFDebugMacroEntry::ReadMacroEntries(
const DWARFDataExtractor &debug_macro_data,
- const DWARFDataExtractor &debug_str_data, const bool offset_is_64_bit,
+ const DWARFDataExtractor &debug_str_data,
+ const DWARFStrOffsetsInfo &str_offsets_info, const bool offset_is_64_bit,
lldb::offset_t *offset, SymbolFileDWARF *sym_file_dwarf,
DebugMacrosSP &debug_macros_sp) {
llvm::dwarf::MacroEntryType type =
@@ -97,6 +105,22 @@
debug_macros_sp->AddMacroEntry(
DebugMacroEntry::CreateUndefEntry(line, macro_str));
break;
+ case DW_MACRO_define_strx:
+ case DW_MACRO_undef_strx:
+ line = debug_macro_data.GetULEB128(offset);
+ str_offset = debug_macro_data.GetULEB128(offset);
+ if (!str_offsets_info.IsValid())
+ // Can't do much in this case, skip all such entries
+ continue;
+ str_offset = str_offsets_info.GetOffset(str_offset);
+ macro_str = debug_str_data.GetCStr(&str_offset);
+ if (type == DW_MACRO_define_strx)
+ debug_macros_sp->AddMacroEntry(
+ DebugMacroEntry::CreateDefineEntry(line, macro_str));
+ else
+ debug_macros_sp->AddMacroEntry(
+ DebugMacroEntry::CreateUndefEntry(line, macro_str));
+ break;
case DW_MACRO_start_file:
line = debug_macro_data.GetULEB128(offset);
debug_line_file_idx = debug_macro_data.GetULEB128(offset);
@@ -113,7 +137,7 @@
else
new_offset = debug_macro_data.GetU32(offset);
debug_macros_sp->AddMacroEntry(DebugMacroEntry::CreateIndirectEntry(
- sym_file_dwarf->ParseDebugMacros(&new_offset)));
+ sym_file_dwarf->ParseDebugMacros(&new_offset, str_offsets_info)));
break;
default:
// TODO: Add support for other standard operations.
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp
@@ -92,8 +92,8 @@
}
const DWARFDataExtractor &DWARFContext::getOrLoadMacroData() {
- return LoadOrGetSection(eSectionTypeDWARFDebugMacro, llvm::None,
- m_data_debug_macro);
+ return LoadOrGetSection(eSectionTypeDWARFDebugMacro,
+ eSectionTypeDWARFDebugMacro, m_data_debug_macro);
}
const DWARFDataExtractor &DWARFContext::getOrLoadRangesData() {
Index: compiler-rt/lib/fuzzer/CMakeLists.txt
===================================================================
--- compiler-rt/lib/fuzzer/CMakeLists.txt
+++ compiler-rt/lib/fuzzer/CMakeLists.txt
@@ -147,7 +147,7 @@
set(cxx_${arch}_merge_dir "${CMAKE_CURRENT_BINARY_DIR}/cxx_${arch}_merge.dir")
file(MAKE_DIRECTORY ${cxx_${arch}_merge_dir})
add_custom_command(TARGET clang_rt.${name}-${arch} POST_BUILD
- COMMAND ${CMAKE_CXX_COMPILER} ${target_cflags} -Wl,--whole-archive "$<TARGET_LINKER_FILE:clang_rt.${name}-${arch}>" -Wl,--no-whole-archive ${dir}/lib/libc++.a -r -o ${name}.o
+ COMMAND ${CMAKE_CXX_COMPILER} ${target_cflags} -Wl,--whole-archive "$<TARGET_LINKER_FILE:clang_rt.${name}-${arch}>" -Wl,--no-whole-archive ${dir}/lib/libc++.a -nodefaultlibs -r -o ${name}.o
COMMAND ${CMAKE_OBJCOPY} --localize-hidden ${name}.o
COMMAND ${CMAKE_COMMAND} -E remove "$<TARGET_LINKER_FILE:clang_rt.${name}-${arch}>"
COMMAND ${CMAKE_AR} qcs "$<TARGET_LINKER_FILE:clang_rt.${name}-${arch}>" ${name}.o
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits