Skip to content

Commit bf86fb7

Browse files
authored
Merge pull request #3 from oco2000/new-dwarf-so
New libdwarf library updates
2 parents 9ecf726 + 4f85b0b commit bf86fb7

File tree

5 files changed

+37
-25
lines changed

5 files changed

+37
-25
lines changed

INSTALL.md

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,10 @@ sudo modprobe usb-storage
3131
Get **qEMU** for ARM to debug your programs without a real device. Install **qemu-system-arm** package using your package manager.
3232

3333
## libelf
34-
Get **libelf** library for elf-files production. Install **libelf1** package
34+
Get **libelf1** library for elf-files production. In most cases you should just install **libelf1** package
3535

3636
## libdwarf
37-
Get **libdwarf** library for debug symbols generation.
38-
You can just copy **libdwarf.so** from this repo to **/usr/lib**. If you see any errors, you should make it by yourself.
39-
Install **dwarfutils** from source:
40-
```bash
41-
apt-get source dwarfutils
42-
```
43-
In the **libdwarf** folder run:
44-
```bash
45-
./configure --enable-shared
46-
make
47-
```
48-
You'll get libdwarf.so
37+
Get **libdwarf1** library for debug symbols generation. In most cases you should just install **libdwarf1** package
4938

5039
## ddd
5140
Get **ddd** (data display debugger). Install **ddd** package.

examples/tester/makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ st_path = ~/src/stlink
1111
$(project).spf.elf: *.spf
1212
$(compiler) options.spf -H -I -O -d -M S\" $(device)\" S\" $(project).spf\" m3forth.spf
1313
arm-none-eabi-objdump -S -w $(project).spf.elf > $(project).spf.lst
14-
# readelf -Ww $(project).spf.elf > $(project).spf.debug
15-
# readelf -aW $(project).spf.elf > $(project).spf.info
14+
readelf -Ww $(project).spf.elf > $(project).spf.debug
15+
readelf -aW $(project).spf.elf > $(project).spf.info
1616
chmod o+x $(project).spf.elf
1717

1818
# debug project with qemu, uart emulation or semihosting and ddd

lib/dwarf/dwarf.spf

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ CREATE temp_symbol /symbol ALLOT
170170

171171
: add_file_symbol ( a u -- ) \ add file name
172172
0 0 2SWAP
173-
STB_LOCAL STT_FILE ELF32_ST_INFO
173+
STB_GLOBAL STT_FILE ELF32_ST_INFO
174174
SHN_ABS
175175
add_symbol
176176
;
@@ -275,7 +275,7 @@ CREATE temp_symbol /symbol ALLOT
275275
: DWARF_ERROR ( f a u -- ) \ if true show string and error message using dwarf_errmsg
276276
ROT IF
277277
." ERROR! " TYPE SPACE
278-
(( error @ )) dwarf_errmsg ASCIIZ> TYPE SPACE BYE
278+
(( error @ )) dwarf_errmsg ASCIIZ> TYPE CR BYE
279279
ELSE 2DROP THEN
280280
;
281281

@@ -450,6 +450,22 @@ CREATE LAST_SUB /sd ALLOT \ last subprogram data
450450

451451
CREATE init_bytes \ taken from c-code compiled elf
452452
0x0C C, 0x0D C, 0 C, \ equals DW_CFA_def_cfa: r13 ofs 0
453+
0x07 C, 0x00 C, 0 C, \ equals DW_CFA_undefined: r0 undefined
454+
0x07 C, 0x01 C, 0 C, \ equals DW_CFA_undefined: r1 undefined
455+
0x07 C, 0x02 C, 0 C, \ equals DW_CFA_undefined: r2 undefined
456+
0x07 C, 0x03 C, 0 C, \ equals DW_CFA_undefined: r3 undefined
457+
0x07 C, 0x04 C, 0 C, \ equals DW_CFA_undefined: r4 undefined
458+
0x07 C, 0x05 C, 0 C, \ equals DW_CFA_undefined: r5 undefined
459+
0x07 C, 0x06 C, 0 C, \ equals DW_CFA_undefined: r6 undefined
460+
0x07 C, 0x07 C, 0 C, \ equals DW_CFA_undefined: r7 undefined
461+
0x07 C, 0x08 C, 0 C, \ equals DW_CFA_undefined: r8 undefined
462+
0x07 C, 0x09 C, 0 C, \ equals DW_CFA_undefined: r9 undefined
463+
0x07 C, 0x0A C, 0 C, \ equals DW_CFA_undefined: r10 undefined
464+
0x07 C, 0x0B C, 0 C, \ equals DW_CFA_undefined: r11 undefined
465+
0x07 C, 0x0C C, 0 C, \ equals DW_CFA_undefined: r12 undefined
466+
0x0C C, 0x0D C, 0 C, \ equals DW_CFA_def_cfa: r13 ofs 0
467+
\ r14 is specified in dwarf_add_frame_cie
468+
\ r15 is pc, no need to specify init state
453469
HERE init_bytes - CONSTANT init_bytes_len
454470

455471
: dwarf_add_frame_cie ( -- )
@@ -505,6 +521,7 @@ EXPORT
505521
\ ========================= create new file with debugging info ============================
506522

507523
O_ELF [IF]
524+
VARIABLE _dw
508525

509526
: DWARF_INIT ( load_addr addr a u -- ) \ create new file
510527
\ load_addr - load address
@@ -521,14 +538,20 @@ O_ELF [IF]
521538
create_section_text \ create .text section
522539

523540
\ init dwarf producer
524-
(( DW_DLC_WRITE DW_DLC_SYMBOLIC_RELOCATIONS OR 0
541+
((
542+
DW_DLC_WRITE DW_DLC_SYMBOLIC_RELOCATIONS OR 0 \ DWORD
525543
['] dwarf_callback_func_c \ function to create elf sections
526-
0
527-
0
528-
0
529-
0
530-
)) dwarf_producer_init_c DUP TO dw
531-
-1 = S" Dwarf producer init failed!" DWARF_ERROR
544+
0 \ errhand
545+
0 \ errarg
546+
0 \ user_data
547+
S" arm" >ASCIIZ \ *isa_name
548+
S" V2" >ASCIIZ \ *dwarf_version
549+
0 \ *extra
550+
_dw \ dw
551+
error \ error
552+
)) dwarf_producer_init
553+
DW_DLV_ERROR = S" Dwarf producer init failed!" DWARF_ERROR
554+
_dw @ TO dw
532555

533556
dwarf_new_CU \ create main CU
534557

lib/dwarf/libdwarf.spf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ REQUIRE 2CONSTANT lib/include/double.f
22

33
BASE @ DECIMAL
44

5-
USE libdwarf.so
5+
USE libdwarf.so.1
66
\ in ubuntu you need to build it from source:
77
\ apt-get source libdwarf-dev
88
\ ./configure --enable-shared --disable-nonshared

libdwarf.so

-997 KB
Binary file not shown.

0 commit comments

Comments
 (0)