x86_64 va_list 结构的格式是什么?
有人有关于 x86_64 ABI(Linux 上使用的)中 va_list
表示的参考吗?我正在尝试调试一些堆栈或参数似乎已损坏的代码,这确实有助于理解我应该看到的内容......
Anyone have a reference for the representation of va_list
in the x86_64 ABI (the one used on Linux)? I'm trying to debug some code where the stack or arguments seem corrupt and it would really help to understand what I'm supposed to be seeing...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
x86-64 System V ABi 文档可能会有所帮助< /a>.尽管很轻,但它是一个参考。
变量参数列表参考从第 54 页开始,然后是第 56-57 页文档
va_list
:The x86-64 System V ABi doc may help. It's a reference, albeit lightweight.
The Variable Argument List reference starts on page 54, then it goes on, page 56-57 documents
va_list
:事实证明,问题是 gcc 将 va_list 设为数组类型。我的函数具有签名:
并且我想将指向
ap
的指针传递给另一个函数,所以我这样做了:不幸的是,数组类型在函数参数列表中衰减为指针类型,因此而不是传递指针对于原始结构,我将一个指针传递给一个指针。
为了解决这个问题,我将代码更改为:
这是我能想到的唯一可移植的解决方案,它解释了
va_list
是数组类型的可能性和不是数组类型的可能性。It turns out the problem was gcc's making
va_list
an array type. My function was of the signature:and I wanted to pass a pointer to
ap
to another function, so I did:Unfortunately, array types decay to pointer types in function argument lists, so rather than passing a pointer to the original structure, I was passing a pointer to a pointer.
To work around the problem, I changed the code to:
This is the only portable solution I could come up with, that accounts for both the possibility that
va_list
is an array type and the possibility that it's not.在i386架构中,va_list是指针类型。然而,在AMD64架构中,它是数组类型。有什么区别?实际上,如果您应用 &对指针类型进行操作,您将得到该指针变量的地址。但无论您申请多少次,对数组类型进行操作,值是相同的,等于这个数组的地址。
那么,在 AMD64 下你应该做什么呢?在函数中传递 va_list 变量的最简单方法就是不带 * 或 & 传递它。操作员。
例如:
它确实有效!而且你不需要担心你有多少争论。
In i386 architecture, the va_list is a pointer type. However, in AMD64 architecture, it is an array type. What is the difference? Actually, if you apply an & operation to a pointer type, you will get the address of this pointer variable. But no matter how many times you apply & operation to an array type, the value is the same, and is equal to the address of this array.
So, what should you do in AMD64? The easiest way to pass variable of va_list in a function is just passing it with no * or & operator.
For example:
It just works! And you don't need to worry about how many arguments you have got.