AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
> ### gdb调试 * 编译(gcc)与调试(gdb) * centos7 安装go和gdb ~~~ yum install -y go gdb ~~~ * main.go ~~~ package main import "unsafe" func main() { s := "hello world!" println(unsafe.Sizeof(s), len(s)) } ~~~ * 开始调试 ~~~ [root@localhost go]# ls main.go [root@localhost go]# go build -gcflags "-N -l" -o main ./main.go [root@localhost go]# gdb main GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-110.el7 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /usr/local/www/go/main...done. (gdb) l 1 package main 2 3 import "unsafe" 4 5 func main() { 6 s := "hello world!" 7 println(unsafe.Sizeof(s), len(s)) 8 } (gdb) b main.go:6 Breakpoint 1 at 0x450b4d: file /usr/local/www/go/main.go, line 6. (gdb) run Starting program: /usr/local/www/go/main Breakpoint 1, main.main () at /usr/local/www/go/main.go:6 6 s := "hello world!" (gdb) p s $1 = 0x45b180 "\001", '\000' <repeats 15 times>, "\305\006\377\023\a\001\001\201\200\255J\000\000\000\000\000T\212G\000\000\000\000\000\200\t\000\000\000k\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\b\000\000\000\000\000\000\000\b\000\000\000\000\000\000\000\270H\337\335\002\b\b2\260\255J\000\000\000\000\000T\212G\000\000\000\000\000\023\037\000\000\000\000\000\000\200\261E\000\000\000\000\000\003\000\000\000\000\000\000\000\b\000\000\000\000\000\000\000\b\000\000\000\000\000\000\000\221U\313q\002\b\b2\260\255J\000\000\000\000\000T\212G\000\000\000\000\000\067\032\000\000\000\000\000\000@\265E\000\000\000\000\000\003\000\000\000\000\000\000\000\020", '\000' <repeats 15 times>...<Address 0x4cc000 out of bounds> (gdb) ptype s type = struct string { uint8 *str; int len; } (gdb) ~~~