DerekSelander / LLDB

A collection of LLDB aliases/regexes and Python scripts to aid in your debugging sessions
GNU General Public License v2.0
1.77k stars 198 forks source link

CFStringCreateWithBytes needed! #12

Closed cclamb closed 5 years ago

cclamb commented 5 years ago

sbt-script-output.txt Keep getting this when I run a variety of commands:

Error [IRForTarget]: Rewriting an Objective-C constant string requires CFStringCreateWithBytes

(this particular one comes from using sbt)

Wouldn't expect it to be a python 3-ism.

Sorry, was on a browser that didn't allow me to attach the text file. The file attached contains the obj-c code that's trying to run and the context of the sbt use.

jasonmolenda commented 5 years ago

When you use an NSString literal in an expression like @"test string", the expression parser creates a call to CFStringCreateWithBytes() to create that object in memory before it can run the expression, a function from CoreFoundation. lldb has not found the symbols to CF/CF itself in your process for some reason -- that's the issue here. image list will show the list of libraries loaded in your process, is CoreFoundation missing? Shouldn't be possible with any GUI app type program.

cclamb commented 5 years ago

Thanks for the detailed explanation of string handling! I'm certain it hasn't loaded it yet. I'm using LLDB to trace the initial execution of safari, and I'm calling search when in the dynamic loader prior to loading libraries. I expect that's exactly the issue.

It seems though that my use case isn't that odd though, perhaps it should be handled?

On Fri, Jan 4, 2019 at 12:53 PM Jason Molenda notifications@github.com wrote:

When you use an NSString literal in an expression like @"test string", the expression parser creates a call to CFStringCreateWithBytes() to create that object in memory before it can run the expression, a function from CoreFoundation. lldb has not found the symbols to CF/CF itself in your process for some reason -- that's the issue here. image list will show the list of libraries loaded in your process, is CoreFoundation missing? Shouldn't be possible with any GUI app type program.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DerekSelander/LLDB/issues/12#issuecomment-451550619, or mute the thread https://github.com/notifications/unsubscribe-auth/AAPUh6ZpB2zAQA-CBg7H9eRto1fUv_plks5u_7EcgaJpZM4ZsS17 .

jasonmolenda commented 5 years ago

from lldb's perspective, you're asking to create a CFString/NSString in the expression before the library that is needed to create that is loaded. The error message is a little inside baseball, but I think failing is the correct response here. The fact that you're using a python command makes the failure a little less obvious - if you had typed the @"" string yourself, there's a better chance you'd be cognizant of what was happening.

DerekSelander commented 5 years ago

Thank you @jasonmolenda for the explanation. Please do pass my regards on to the lldb team for such a great tool.

@cclamb, it sounds like for this situation, the sbt command would not be a good tool for your situation. The sbt command uses the Obj-C runtime to re-symbolicate stripped method names. It will not do anything to symbolicate stripped C/C++ code. If you are tracing code at module loading that doesn't have CoreFoundation loaded yet, this implies that the function was called via a __attribute__((constructor)) type of declaration (implying C/C++ code) and not a +[NSObject load]

You can quickly monitor these functions via the DYLD_PRINT_INITIALIZERS environment variable (see man dyld(1))

DYLD_PRINT_INITIALIZERS=1 /Applications/Safari.app/Contents/MacOS/Safari

From there, you can use LLDB to see if there's a name for the function using lldb. Use LLDB's image lookup -a 0xaddress_here or my info command (found in this repo)