lldb does not allow to set breakpoint nor list the source file

2

Having the following assembly source:

# hello_asm.s
# as hello_asm.s -o hello_asm.o
# ld hello_asm.o -e _main -o hello_asm
.section __DATA,__data
str:
  .asciz "Hello world!\n"

.section __TEXT,__text
.globl _main
_main:
  movl $0x2000004, %eax           # preparing system call 4
  movl $1, %edi                    # STDOUT file descriptor is 1
  movq str@GOTPCREL(%rip), %rsi   # The value to print
  movq $100, %rdx                 # the size of the value to print
  syscall

#
# EXITING
#
  movl $0, %ebx
  movl $0x2000001, %eax           # exit 0
  syscall

by compiling and linking with the following instructions:

as sum.s -g -o sum.o
ld -arch x86_64 -e main -L /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/lib -lSystem sum.o -o sum

and by trying to debug it on LLDB, I get the following result:

❯❯❯❯ lldb sum.o                                                                                                                   ~/D/test
(lldb) target create "sum.o"
Current executable set to '/Users/mbertamini/Downloads/test/sum.o' (x86_64).
(lldb) list
(lldb) b 16
error: No selected frame to use to find the default file.
error: No file supplied and no default file available.
(lldb)

This is the dwarf:

❯❯❯❯ dwarfdump sum.o                                                                                                                     ~/D/t/summ
sum.o:  file format Mach-O 64-bit x86-64

.debug_info contents:
0x00000000: Compile Unit: length = 0x00000094 version = 0x0004 abbr_offset = 0x0000 addr_size = 0x08 (next unit at 0x00000098)

0x0000000b: DW_TAG_compile_unit
              DW_AT_stmt_list   (0x00000000)
              DW_AT_low_pc  (0x0000000000000000)
              DW_AT_high_pc (0x0000000000000026)
              DW_AT_name    ("sum.s")
              DW_AT_comp_dir    ("<filepath>")
              DW_AT_producer    ("Apple clang version 12.0.0 (clang-1200.0.32.27)")
              DW_AT_language    (DW_LANG_Mips_Assembler)

0x0000007e:   DW_TAG_label
                DW_AT_name  ("main")
                DW_AT_decl_file ("<filepath-file>")
                DW_AT_decl_line (10)
                DW_AT_low_pc    (0x0000000000000000)
                DW_AT_prototyped    (0x00)

0x00000095:     DW_TAG_unspecified_parameters

0x00000096:     NULL

0x00000097:   NULL
❯❯❯❯ as -v                                                                                                                               ~/D/t/summ
Apple clang version 12.0.0 (clang-1200.0.32.27)
Target: x86_64-apple-darwin20.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1as -triple x86_64-apple-macosx11.0.0 -filetype obj -main-file-name - -target-cpu penryn -fdebug-compilation-dir /Users/mbertamini/Downloads/test/summ -dwarf-debug-producer "Apple clang version 12.0.0 (clang-1200.0.32.27)" -dwarf-version=4 -mrelocation-model pic -o a.out -

what's the problem? How am I supposed to do?

macos
assembly
lldb
macos-big-sur
asked on Stack Overflow Jan 17, 2021 by Bertuz • edited Jan 17, 2021 by Bertuz

1 Answer

3

The issue is that the source file for which the debugging info is mapped should be used (sum.s):

$ as sum.s -g -o sum.o
$ ld -arch x86_64 -e _main -macosx_version_min 10.13 -lSystem sum.o -o sum
$ lldb sum
(lldb) target create "sum"
Current executable set to 'sum' (x86_64).
(lldb) b sum.s:16
Breakpoint 1: where = sum`main + 26, address = 0x0000000100000fac
(lldb) 

When assembling use the -O0 optimization along the -g Code Generation Option.
(This is important only when compiling with clang; this doesn't apply with as)

lldb: resolving breakpoints to locations

answered on Stack Overflow Jan 18, 2021 by l'L'l • edited Jan 18, 2021 by l'L'l

User contributions licensed under CC BY-SA 3.0