符号(方法和函数)的基地址(程序计数器)不匹配.减 1 [英] Base addresses (Program Counters) of symbols (methods and functions) do not match. Off by 1

查看:32
本文介绍了符号(方法和函数)的基地址(程序计数器)不匹配.减 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一些代码可以向我发送未捕获异常的堆栈跟踪.

I have some code in my app that sends me the stack trace of uncaught exceptions.

"0   CoreFoundation   0x3ad073ff <redacted> + 186",
"1   libobjc.A.dylib  0x39412963 objc_exception_throw + 30",
"2   CoreFoundation   0x3ad0729d <redacted> + 0",
"3   Foundation       0x39f3b7b3 <redacted> + 90",
"4   UIKit            0x34a3ae29 <redacted> + 4184",
"5   MyApp            0x0001feab -[MAMyClassA firstMethod:withParameter1:andParameter2:] + 374",
"6   MyApp            0x000f76b5 -[MAMyClassB secondMethod:withParameter1:andParameter2:] + 164",
"7   UIKit            0x34bd0fe1 <redacted> + 84",
"8   UIKit            0x34af2047 <redacted> + 70",
"9   UIKit            0x34af1ffb <redacted> + 30",
"10  UIKit            0x34af1fd5 <redacted> + 44",
...

如您所见,Apple 的大部分方法都被替换为 .我已经能够使用 nm 从 Apple 的库中提取符号及其相应的基地址,但地址不匹配.他们是 1.

As you can see, most of Apple's methods are replaced with <redacted>. I have been able to extract the symbols and their corresponding base addresses from Apple's libraries using nm, but the addresses do not match. They are off by 1.

我已经按照此处的说明计算了地址:iOS 崩溃报告:atos 未按预期工作.

I have calculated the address as explained here: iOS crash reports: atos not working as expected.

Symbol address = (base address of framework) - (base address of symbol from crash report) + (virtual memory slide [vmaddr]).

例如,我得到的是 0xC2345,但 nm 返回的实际符号地址是 0xC2344.我知道这是正确的符号.我在不同的崩溃报告中用不同的框架(UIKit、Foundation、CoreFoundation 等)中的不同地址尝试过这个,结果是一样的:值总是减去 1.我必须从我得到的值中减去 1崩溃报告以获取 nm 提供的正确"地址.

For example, I'm getting 0xC2345, but the actual symbol address returned by nm is 0xC2344. I know that this is the right symbol. I have tried this with different addresses in different frameworks (UIKit, Foundation, CoreFoundation, etc.) in different crash reports and the result is the same: the value is always off by 1. I have to subtract 1 from what I get in the crash report to get the "right" address as provided by nm.

当我输入这个问题时,我发现了这个:错误的方法来自 otool for armv7 的实现地址?.

As I am typing this question, I found this: Wrong method implementation address from otool for armv7?.

这是否意味着每次有地址查找时都必须执行以下逻辑?

Does that mean that every time I have an address to look up I have to perform the following logic?

if ((symbol address) mod 2 == 1) {
  // This is a thumb instruction so it may be 2 or four bytes
  Subtract 1 from the symbol address and then use it to lookup the symbol.
}
else {
  // This is a standard 4-byte ARM instruction.
  Perform symbol lookup with the address as is.
}

预先感谢您的任何帮助或指导.

Thanks in advance for any help or direction.

推荐答案

PC 中的 LSB 显示当前的执行模式.如果该位为 0,则它是 ARM,如果它被设置为 1,则在 Thumb 模式下执行.所以是的,你会得到这样的真实地址:

The LSB in the PC shows the current execution-mode. If the bit is 0 then it's ARM, if it's set to 1 then the execution is done in Thumb-Mode. So yes, you'll get the real address like this:

real_address = address & ~1;

和当前的执行模式是这样的:

And the current execution mode like this:

is_thumb_mode = address & 1;

现在的大多数代码都将被编译为 Thumb-2,因为它只有少数几个地方缺少真正的"ARM 代码,并且通常可以节省大约 30% 的代码大小.

Most code these days will be compiled to Thumb-2 as it has only a few areas where it lacks behind "real" ARM-code and usually saves about 30% in code size.

这篇关于符号(方法和函数)的基地址(程序计数器)不匹配.减 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆