---
# System prepended metadata

title: debug

---

debug
===

gdb:

看structure offset
&((struct xxx*)0)->data

 cc -gdwarf-2 -g3，然後配合 gdb 的 macro expand 指令，就可以展開 macro 了！


使用gdb python功能
/local/patrick/build/gdb-8.1.50-rv64/gdb/gdb --data-directory /local/patrick/build/gdb-8.1.50-rv64/gdb/data-directory
(gdb) set auto-load safe-path /NOBACKUP/atcsqa06/zong/kernel/linux-riscv/linux/

列出struct offset (after 8.1 version)
ptype /o struct struct17

gcc:

dump predefined macros
nds32le-linux-gcc -dM -E - < /dev/null


Link:
compile link detail: -Wl,--verbose

runtime debug ld: export LD_DEBUG=xxx
```
Vaild option for LD_DEBUG
libs	display library search paths
reloc	display relocation processing
files	display progress for input file
symbols	display symbol table processing
bindings	display information about symbol binding
versions	display version dependencies
all	all previous options combined
statistics	display relocation statistic
unused	determined unused DSOs
help	display this help message and exit
```

Linux:
- memblock
```
 如果需要了解memblock的详细分配流程，可以通过在bootargs中加入“memblock=debug”。
 在内核启动后，通过/proc/kmsg查看调试信息。

查看内存地址范围和reserved区域可以通过：

/sys/kernel/debug/memblock/memory 

/sys/kernel/debug/memblock/reserved
```
- devmem
```
在userspace直接access pa

# devmem
# devmem 0x2010000 64  顯示 64 位元長度 內容
# devmem 0x2010000 32  顯示 32 位元長度 內容
# devmem 0x2010000 32 15 將此位置寫入值15

```