diff options
author | Greg Clayton <gclayton@apple.com> | 2018-03-15 05:13:15 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2018-03-15 05:13:15 +0000 |
commit | 9cc222c80de913d62b8a8d16c1c1dcc9665febb0 (patch) | |
tree | 7f99b7208fdc153cf0880f88faef883281b344e3 | |
parent | 1f8da3ae19fa91780218e6c6430aba52ef429936 (diff) | |
download | bcm5719-llvm-9cc222c80de913d62b8a8d16c1c1dcc9665febb0.tar.gz bcm5719-llvm-9cc222c80de913d62b8a8d16c1c1dcc9665febb0.zip |
Fix a bug in "target.source-map" where we would resolve unmapped paths incorrectly
When using:
(lldb) settings set target.source-map ./ /path/to/source
LLDB would fail to set a source file and line breakpoint with:
(lldb) breakpoint set --file /path/to/source/main.c --line 2
Because code in the target was undoing the remapping of "/path/to/source/main.c" to "./main.c" and then it would resolve this path, which would append the current working directory to the path. We don't want to resolve paths that we unmap.
Test case added.
Differential Revision: https://reviews.llvm.org/D44502
llvm-svn: 327600
3 files changed, 438 insertions, 1 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/source-map/TestTargetSourceMap.py b/lldb/packages/Python/lldbsuite/test/functionalities/source-map/TestTargetSourceMap.py new file mode 100644 index 00000000000..6bcd9c92f8c --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/source-map/TestTargetSourceMap.py @@ -0,0 +1,41 @@ +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * + + +class TestTargetSourceMap(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @no_debug_info_test + def test_source_map(self): + """Test target.source-map' functionality.""" + # Set the target soure map to map "./" to the current test directory + src_dir = self.getSourceDir() + src_path = os.path.join(src_dir, "main.c") + yaml_path = os.path.join(src_dir, "a.yaml") + yaml_base, ext = os.path.splitext(yaml_path) + obj_path = self.getBuildArtifact(yaml_base) + self.yaml2obj(yaml_path, obj_path) + + def cleanup(): + if os.path.exists(obj_path): + os.unlink(obj_path) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + # Create a target with the object file we just created from YAML + target = self.dbg.CreateTarget(obj_path) + + # Set a breakpoint before we remap source and verify that it fails + bp = target.BreakpointCreateByLocation(src_path, 2) + self.assertTrue(bp.GetNumLocations() == 0, + "make sure no breakpoints were resolved without map") + src_map_cmd = 'settings set target.source-map ./ "%s"' % (src_dir) + self.dbg.HandleCommand(src_map_cmd) + + # Set a breakpoint after we remap source and verify that it succeeds + bp = target.BreakpointCreateByLocation(src_path, 2) + self.assertTrue(bp.GetNumLocations() == 1, + "make sure breakpoint was resolved with map") diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/source-map/a.yaml b/lldb/packages/Python/lldbsuite/test/functionalities/source-map/a.yaml new file mode 100644 index 00000000000..2ffb94cb775 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/source-map/a.yaml @@ -0,0 +1,396 @@ +--- !mach-o +FileHeader: + magic: 0xFEEDFACF + cputype: 0x01000007 + cpusubtype: 0x00000003 + filetype: 0x0000000A + ncmds: 6 + sizeofcmds: 1376 + flags: 0x00000000 + reserved: 0x00000000 +LoadCommands: + - cmd: LC_UUID + cmdsize: 24 + uuid: D37CC773-C218-3F97-99C9-CE4E77DDF2CE + - cmd: LC_SYMTAB + cmdsize: 24 + symoff: 4096 + nsyms: 2 + stroff: 4128 + strsize: 28 + - cmd: LC_SEGMENT_64 + cmdsize: 72 + segname: __PAGEZERO + vmaddr: 0 + vmsize: 4294967296 + fileoff: 0 + filesize: 0 + maxprot: 0 + initprot: 0 + nsects: 0 + flags: 0 + - cmd: LC_SEGMENT_64 + cmdsize: 232 + segname: __TEXT + vmaddr: 4294967296 + vmsize: 4096 + fileoff: 0 + filesize: 0 + maxprot: 7 + initprot: 5 + nsects: 2 + flags: 0 + Sections: + - sectname: __text + segname: __TEXT + addr: 0x0000000100000FA0 + size: 15 + offset: 0x00000000 + align: 4 + reloff: 0x00000000 + nreloc: 0 + flags: 0x80000400 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + - sectname: __unwind_info + segname: __TEXT + addr: 0x0000000100000FB0 + size: 72 + offset: 0x00000000 + align: 2 + reloff: 0x00000000 + nreloc: 0 + flags: 0x00000000 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + - cmd: LC_SEGMENT_64 + cmdsize: 72 + segname: __LINKEDIT + vmaddr: 4294971392 + vmsize: 4096 + fileoff: 4096 + filesize: 60 + maxprot: 7 + initprot: 1 + nsects: 0 + flags: 0 + - cmd: LC_SEGMENT_64 + cmdsize: 952 + segname: __DWARF + vmaddr: 4294975488 + vmsize: 4096 + fileoff: 8192 + filesize: 563 + maxprot: 7 + initprot: 3 + nsects: 11 + flags: 0 + Sections: + - sectname: __debug_line + segname: __DWARF + addr: 0x0000000100002000 + size: 60 + offset: 0x00002000 + align: 0 + reloff: 0x00000000 + nreloc: 0 + flags: 0x00000000 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + - sectname: __debug_pubnames + segname: __DWARF + addr: 0x000000010000203C + size: 27 + offset: 0x0000203C + align: 0 + reloff: 0x00000000 + nreloc: 0 + flags: 0x00000000 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + - sectname: __debug_pubtypes + segname: __DWARF + addr: 0x0000000100002057 + size: 26 + offset: 0x00002057 + align: 0 + reloff: 0x00000000 + nreloc: 0 + flags: 0x00000000 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + - sectname: __debug_aranges + segname: __DWARF + addr: 0x0000000100002071 + size: 48 + offset: 0x00002071 + align: 0 + reloff: 0x00000000 + nreloc: 0 + flags: 0x00000000 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + - sectname: __debug_info + segname: __DWARF + addr: 0x00000001000020A1 + size: 75 + offset: 0x000020A1 + align: 0 + reloff: 0x00000000 + nreloc: 0 + flags: 0x00000000 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + - sectname: __debug_abbrev + segname: __DWARF + addr: 0x00000001000020EC + size: 52 + offset: 0x000020EC + align: 0 + reloff: 0x00000000 + nreloc: 0 + flags: 0x00000000 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + - sectname: __debug_str + segname: __DWARF + addr: 0x0000000100002120 + size: 28 + offset: 0x00002120 + align: 0 + reloff: 0x00000000 + nreloc: 0 + flags: 0x00000000 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + - sectname: __apple_names + segname: __DWARF + addr: 0x0000000100002160 + size: 60 + offset: 0x00002160 + align: 0 + reloff: 0x00000000 + nreloc: 0 + flags: 0x00000000 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + - sectname: __apple_namespac + segname: __DWARF + addr: 0x000000010000219C + size: 36 + offset: 0x0000219C + align: 0 + reloff: 0x00000000 + nreloc: 0 + flags: 0x00000000 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + - sectname: __apple_types + segname: __DWARF + addr: 0x00000001000021C0 + size: 79 + offset: 0x000021C0 + align: 0 + reloff: 0x00000000 + nreloc: 0 + flags: 0x00000000 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + - sectname: __apple_objc + segname: __DWARF + addr: 0x000000010000220F + size: 36 + offset: 0x0000220F + align: 0 + reloff: 0x00000000 + nreloc: 0 + flags: 0x00000000 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 +LinkEditData: + NameList: + - n_strx: 2 + n_type: 0x0F + n_sect: 1 + n_desc: 16 + n_value: 4294967296 + - n_strx: 22 + n_type: 0x0F + n_sect: 1 + n_desc: 0 + n_value: 4294971296 + StringTable: + - '' + - '' + - __mh_execute_header + - _main +DWARF: + debug_str: + - '' + - obj2yaml + - main.c + - . + - main + - int + debug_abbrev: + - Code: 0x00000001 + Tag: DW_TAG_compile_unit + Children: DW_CHILDREN_yes + Attributes: + - Attribute: DW_AT_producer + Form: DW_FORM_strp + - Attribute: DW_AT_language + Form: DW_FORM_data2 + - Attribute: DW_AT_name + Form: DW_FORM_strp + - Attribute: DW_AT_stmt_list + Form: DW_FORM_sec_offset + - Attribute: DW_AT_comp_dir + Form: DW_FORM_strp + - Attribute: DW_AT_low_pc + Form: DW_FORM_addr + - Attribute: DW_AT_high_pc + Form: DW_FORM_data4 + - Code: 0x00000002 + Tag: DW_TAG_subprogram + Children: DW_CHILDREN_no + Attributes: + - Attribute: DW_AT_low_pc + Form: DW_FORM_addr + - Attribute: DW_AT_high_pc + Form: DW_FORM_data4 + - Attribute: DW_AT_frame_base + Form: DW_FORM_exprloc + - Attribute: DW_AT_name + Form: DW_FORM_strp + - Attribute: DW_AT_decl_file + Form: DW_FORM_data1 + - Attribute: DW_AT_decl_line + Form: DW_FORM_data1 + - Attribute: DW_AT_type + Form: DW_FORM_ref4 + - Attribute: DW_AT_external + Form: DW_FORM_flag_present + - Code: 0x00000003 + Tag: DW_TAG_base_type + Children: DW_CHILDREN_no + Attributes: + - Attribute: DW_AT_name + Form: DW_FORM_strp + - Attribute: DW_AT_encoding + Form: DW_FORM_data1 + - Attribute: DW_AT_byte_size + Form: DW_FORM_data1 + debug_aranges: + - Length: + TotalLength: 44 + Version: 2 + CuOffset: 0 + AddrSize: 8 + SegSize: 0 + Descriptors: + - Address: 0x0000000100000FA0 + Length: 15 + debug_pubnames: + Length: + TotalLength: 23 + Version: 2 + UnitOffset: 0 + UnitSize: 75 + Entries: + - DieOffset: 0x0000002A + Name: main + debug_pubtypes: + Length: + TotalLength: 22 + Version: 2 + UnitOffset: 0 + UnitSize: 75 + Entries: + - DieOffset: 0x00000043 + Name: int + debug_info: + - Length: + TotalLength: 71 + Version: 4 + AbbrOffset: 0 + AddrSize: 8 + Entries: + - AbbrCode: 0x00000001 + Values: + - Value: 0x0000000000000001 + - Value: 0x000000000000000C + - Value: 0x000000000000000A + - Value: 0x0000000000000000 + - Value: 0x0000000000000011 + - Value: 0x0000000100000FA0 + - Value: 0x000000000000000F + - AbbrCode: 0x00000002 + Values: + - Value: 0x0000000100000FA0 + - Value: 0x000000000000000F + - Value: 0x0000000000000001 + BlockData: + - 0x56 + - Value: 0x0000000000000013 + - Value: 0x0000000000000001 + - Value: 0x0000000000000001 + - Value: 0x0000000000000043 + - Value: 0x0000000000000001 + - AbbrCode: 0x00000003 + Values: + - Value: 0x0000000000000018 + - Value: 0x0000000000000005 + - Value: 0x0000000000000004 + - AbbrCode: 0x00000000 + Values: + debug_line: + - Length: + TotalLength: 56 + Version: 2 + PrologueLength: 29 + MinInstLength: 1 + DefaultIsStmt: 1 + LineBase: 251 + LineRange: 14 + OpcodeBase: 13 + StandardOpcodeLengths: [ 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 ] + IncludeDirs: + Files: + - Name: main.c + DirIdx: 0 + ModTime: 0 + Length: 0 + Opcodes: + - Opcode: DW_LNS_extended_op + ExtLen: 9 + SubOpcode: DW_LNE_set_address + Data: 4294971296 + - Opcode: DW_LNS_copy + Data: 4294971296 + - Opcode: DW_LNS_set_column + Data: 2 + - Opcode: DW_LNS_set_prologue_end + Data: 2 + - Opcode: 0xC9 + Data: 2 + - Opcode: DW_LNS_advance_pc + Data: 2 + - Opcode: DW_LNS_extended_op + ExtLen: 1 + SubOpcode: DW_LNE_end_sequence + Data: 2 +... diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 1464d4c999c..5cbda0d3baf 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -330,7 +330,7 @@ BreakpointSP Target::CreateBreakpoint(const FileSpecList *containingModules, ConstString remapped_path; if (GetSourcePathMap().ReverseRemapPath(ConstString(file.GetPath().c_str()), remapped_path)) - remapped_file.SetFile(remapped_path.AsCString(), true); + remapped_file.SetFile(remapped_path.AsCString(), false); else remapped_file = file; |