c++ - In a release build by GCC, i.e., without -g flag, is register info trustable? - Stack Overflow

I am debugging a program crash of a released build, that is, no debug info is available in GDB, all I c

I am debugging a program crash of a released build, that is, no debug info is available in GDB, all I can get is a callstack of the crash point. Due to some restrictions, using a debug build is not on the table.

However, I was wondering whether I can still get the funtion args in the callframe? say, by p $rdi in GDB, can I still get the first arg of the real scene of current function frame?

I am debugging a program crash of a released build, that is, no debug info is available in GDB, all I can get is a callstack of the crash point. Due to some restrictions, using a debug build is not on the table.

However, I was wondering whether I can still get the funtion args in the callframe? say, by p $rdi in GDB, can I still get the first arg of the real scene of current function frame?

Share Improve this question edited Mar 25 at 10:14 PkDrew asked Mar 25 at 10:01 PkDrewPkDrew 9472 gold badges7 silver badges23 bronze badges 5
  • 1 .. If the function has not clobbered RDI previously, yes. – Botje Commented Mar 25 at 10:04
  • 4 Also note that -g is orthogonal to optimisations. It is common practice to compile with -g and split off the debug information before publishing the executable. – Botje Commented Mar 25 at 10:05
  • 2 Optimizations are controlled by -O, -g just means debug symbols. Under optimizations, the thing that affects registers is that there might not be a function call at all if it is inlined. The function call convention is otherwise guaranteed to obey the same ABI. – Passer By Commented Mar 25 at 10:12
  • @PasserBy, yeah I'd better use an another way expressing it, I'll change the title. – PkDrew Commented Mar 25 at 10:13
  • Can you do a optimized/release build with debug symbols (-g)? That would make your life a little easier. – Jesper Juhl Commented Mar 25 at 11:50
Add a comment  | 

1 Answer 1

Reset to default 1

In short, no. RDI is call-clobbered in the SYSV ABI, and GCC can dynamically reassign registers based as needed. If the argument that was in RDI is already consumed, GCC knows it can freely reuse RDI for other purposes. And under register pressure, GCC may push RDI to the stack.

When the function at hand is not a leaf function, there's an additional observation. GCC will not blindly try to restore RDI to its old value after calling another function. That's just a special case of "freely reuse RDI".

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744204913a4563054.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信