可视化debug linux系统的ECU

前段时间真的是太没时间了,耽误了好久,还记得有两个博客没写完的,一个就是基于openssl实现tls+socket的安全通信-2;还有就是一个我是如何从MCU开发转到linux开发,还想趁着写这篇文章再回顾一下编译链接的原理。前几个月基本都是“纯软件开发”,这周开始了要开始在ECU上实际运行了,虽然我之前在linux服务器已经测试过了,但偶尔还是会出现一些问题,比如coredump。解决这个问题没有比debug更好用的方法了。

一、 关于vscode

  Visual Studio Code(简称VSCode/vscode)是一款由微软开发且跨平台的免费源代码编辑器。vscode实在太好用了,第二份工作以前一直在用Source Insight,接触到vscode后,就为了AUTOSAR源码时时用过一次了,主要是vscode有各种插件,在工程不大时,搜索、goto简直不要太好用,还可以很简单的在各个平台debug程序。

二、 我的debug之路

  关于IDE,我是单片机开发出身,本身是以IDE编译调试为主(最近看很多也开始使用Makefile了),基本上市面上的嵌入式IDE都多多少少用过了,但是我觉得visual studio(简称vs)是独一档的,以前领导要求代码都至少需要具备跨linux、windows平台,所以我都是现在windows上使用开发、调试好后,直接再搬到linux简单测试、修改就ok。vs调试多线程实在太方便了,单步调试时不会因为多线程瞎跑,,更关键的是vs还可以远程调试linux程序,而且基本上和调试windows环境下的没什么区别,还有就是变量改变触发程序停止用来调试异常简直太无敌。我愿称vs上开发代码是飞机导弹。当然即使在windows上我经常使用vscode看代码,尤其阅读不是自己的写代码时。
  新公司配的是macbookpro,虽然也申请了windows电脑,但是性能实在太渣,并且跨linux、windows优先级不高,所以就慢慢还是用vscode来开发、调试代码,一直使用的vscode远程登录到linux服务器,然后使用gdb来调试。这个相对vs来说就弱多了,只有变量监控、断点等极少的功能,并且变量还不能很方便的选择16进制显示还是10进制显示,要想16进制显示变量,必须手动将变量(包括局部变量)add watch,然后在变量后面加上,h或则,x,如下图所示:

10进制显示变量
16进制显示变量

虽然比不上vs debug上的飞机导弹,而且多线程单步调试迷之跳转也是很无语,但是用起来还是不错的,怎么也算的坦克飞机了。
  这周刚把代码放到板子上就coredump了,,gdb exe core虽然看到了coredump的位置,但是还是没有头绪,因为出现coredump的地方是一个递归函数。先是gdb命令行调试,命令行设断点、单步运行,小米加步枪真是太难了,但是听说大神都是这样来调试的Orz;所以后面又在linux服务器准备测试条件上重新复现了一遍,解决了问题。显然我是不能在ECU上装个vscode server了,我怕领导知道了把我打死,不过好在天生乐观,做好了我要成为gdb命令调试大神的准备,实在不行就日志调试法。但是在某个晚上,突然想起了,既然windows下的vs的能够远程调试linux,那linux是不是也能远程调试linux呢?经过简单分析,只要ECU上能够运行gdb server,linux服务器远程client,不就成了。先是在板子上搜了一下,嘿,好家伙,板子上还是有的。
ECU上的gdbserver在发光

1. vscode调试ECU验证

  有了上面想法后,我又经过进一步的分析,真的是可行的,显示在Google搜索了一番,验证了可行性,然后又开始找应该如何做。估计这样做的人并不是很多,所以找了半天也没找到有比较好的教程。我知道调试相关的配置都是在launch.json上,所以我又去vscode官网去了找launch.json的说明,看到了下图,我就开始配置了。

Customizing GDB or LLDB

上图官网链接:launch-json-reference.

2. vscode调试ECU配置

  我先是配置好了gdbserver,毕竟在ECU上gdbserver --help一下就都有了,

gdbserver --help
.
所以我一下就讲ecu端的给配置好了:gdbserver 172.20.1.199:21314 udsd,运行后如下图所示:
rungdbserver

然后就是配置vscode端了,也就是gbd client端,期间也有很好多次的试错,具体过程不表了,总结如下:
1. gdbserver --help图中显示的HOST是client端的IP,而不是gdbserver端的IP。
2. miDebuggerPath中的路径是指的vscode实际运行的机器上的工具,而不是ECU端能够运行的工具,交叉编译环境下需要及其的注意这一点。ps:我自己用源码编译出来的工具试了也没成功,最后找供应商用yocto制作出来的工具链上带的x86_64的工具就可以了。
vscode上的配置如下图,默认读者已经会vscode上的debug了:
vscode gbd配置
.

3. 调试前的最后障碍

  做完上面的配置后,我以为这么简单就可以debug了。发现只能运行但是不能打断点,看了下cmake生成的Makefile,发现生成的Makefile上flag显示的是NDEBUG:

makefile NDEBUG
。但是我已经在CMakeLists.txt上配置set(CMAKE_BUILD_TYPE Debug),依然没有生效。后面我就使用了,add_definitions("-g")强制来加上-g选项,果然可以debug了。到这就大功搞成了,领导再也不用担心我效率不高了。

4. 最后障碍的刨根问底

  作为有技术洁癖(自大)的人,不太能忍受上面的“肮脏”解决办法,就去了问了大神Ricky(褒义词的全能神),好家伙好家伙,大神敲键盘的速度,在我描述完问题之前就把引发问题的地方打开并且演示完毕了。速度太快了,我不想忍了。在大神的解释下,原因就是交叉编译时会使用toolchain上的cmake配置,即将交叉编译必须的一些选项配置好,而toolchain上默认是发布的release版本而不是debug,并且优先级是最高的,所以会覆盖自己在cmake上的配置。toolchain.cmake配置如下图:

toolchain.cmake NDEBUG

三、最后呢

  这篇文章标志着我要开始在ECU上调试了,也暗示着我4 5个月的重构开始进入了最后阶段了。这几个月其实压力还是蛮大的,统计了下代码量,17000行的代码超过了我去年一年的代码量,目前来看是达到了跳槽的目的,放弃team leader还是很值当的。并且熟能生巧,前段时间没太有时间就是因为我自己写完了也会再思考思考还有没有改进的空间,代码量上来了,关于结构、耦合性是会不由自主就去考虑的。现在进入了新阶段,行百里者半九十,希望能有个好的结果。

评论

  1. 2年前
    2022-7-26 4:27:32

    Im pretty pleased to find this great site. I need to to thank you for ones time for this particularly fantastic read!! I definitely loved every little bit of it and I have you saved as a favorite to see new stuff on your blog.

  2. 2年前
    2022-7-30 0:39:38

    A fascinating discussion is definitely worth comment. I do think that you ought to publish more about this topic, it may not be a taboo subject but typically people dont speak about such issues. To the next! Many thanks!!

  3. 2年前
    2022-8-18 9:13:07

    Extraordinarily interesting knowledge that you have mentioned, thanks so much for submitting. Sheldon Ulvan

  4. 2年前
    2022-8-19 18:47:33

    Wonderful post! We will be linking to this particularly great content on our site. Keep up the great writing. Ike Wrede

  5. 2年前
    2022-8-20 5:30:06

    Thanks a lot for the blog. Thanks Again. Want more. Heath Leyda

  6. 2年前
    2022-8-20 11:16:00

    Hi colleagues, nice article and fastidious arguments commented here, I am genuinely enjoying by these. Saul Ungerland

  7. 2年前
    2022-8-20 20:45:48

    Amazing! Its genuinely remarkable article, I have got much clear idea concerning from this post. Lino Solimeno

  8. Itís difficult to find knowledgeable people about this subject, but you sound like you know what youíre talking about! Thanks

  9. 2年前
    2022-8-23 9:48:19

    What a data of un-ambiguity and preserveness of valuable experience regarding unexpected emotions. Freddy Syta

  10. 2年前
    2022-8-28 0:35:36

    What a material of un-ambiguity and preserveness of precious knowledge regarding unexpected feelings. Shon Balicki

  11. 2年前
    2022-8-28 2:42:57

    Enjoyed every bit of your post. Really looking forward to read more. Awesome. Nick Trine

  12. 2年前
    2022-9-02 19:45:15

    Having read this I thought it was rather informative. Rusty Goeldner

  13. 2年前
    2022-9-04 23:27:06

    I really enjoy the blog article. Much thanks again. Keep writing. Trent Caponi

  14. 2年前
    2022-9-06 23:01:52

    I every time emailed this blog post page to all my contacts, as if like to read it then my friends will too. Emmett Correll

  15. 2年前
    2022-9-07 0:08:35

    This is my first time pay a visit at here and i am genuinely impressed to read all at single place. Weldon Vires

  16. 2年前
    2022-9-07 3:17:15

    This website is my inhalation, very good design and Perfect subject matter. Omer Kassebaum

  17. 2年前
    2022-9-07 7:12:11

    Great site! I am loving it!! Will be back later to read some more. I am bookmarking your feeds also. Felipe Hartzell

  18. 2年前
    2022-9-08 3:23:01

    WordPress.com is really a hosted Edition of WordPress. Javier Quader

  19. 1年前
    2022-12-03 18:24:00

    Heya i'm for the first time here. I came across this board and I find It really useful & it helped me
    out a lot. I hope to give something back and help others like you aided me.

    Feel free to surf to my blog ... <a href="http://tinyurl.com/2pgzps2k">tracfone special coupon 2022</a>

  20. 1年前
    2022-12-21 4:17:40

    Thanks for sharing, this is a fantastic blog article. Really looking forward to read more. Keep writing. William Annicchiarico

  21. 1年前
    2022-12-21 12:18:37

    Wonderful, what a web site it is! This web site gives useful facts to us, keep it up. Leonardo Crossfield

  22. 1年前
    2022-12-25 2:24:00

    Thanks, Jack. Gardening has been a lifelong pleasure. Clair Panek

  23. 1年前
    2022-12-29 18:15:41

    Really nice design and superb content material, nothing at all else we need :D. Alfredo Cooey

  24. 待审核
    1年前
    2023-2-24 14:01:48

    I know this iff offf topic buut I'm looking into tarting
    mmy own bllg andd wwas curikous what all is required to geet setup?
    I'm assumikng having a log lie yoiurs would coet a pretty penny?

    I'm not vvery web savvy so I'm noot 100% sure.
    Anny tips orr advice would bee greatly appreciated.
    Thank you

  25. 待审核
    1年前
    2023-3-07 15:19:09

    可视化debug linux系统的ECU - 汽车与it技术学习与分享
    [url=http://www.g69rv0m00iq124k8fz4398ud6xzeh1h4s.org/]utfxwbkr[/url]
    <a href="http://www.g69rv0m00iq124k8fz4398ud6xzeh1h4s.org/">atfxwbkr</a&gt;
    tfxwbkr http://www.g69rv0m00iq124k8fz4398ud6xzeh1h4s.org/

  26. 待审核
    1年前
    2023-3-23 14:13:11

    可视化debug linux系统的ECU - 汽车与it技术学习与分享
    oeczyqdt http://www.gf771ixa84xqp7u3f65b0foqk6q96081s.org/
    [url=http://www.gf771ixa84xqp7u3f65b0foqk6q96081s.org/]uoeczyqdt[/url]
    <a href="http://www.gf771ixa84xqp7u3f65b0foqk6q96081s.org/">aoeczyqdt</a&gt;

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇