{"id":13338683,"url":"https://github.com/DerekSelander/lldb_fix","last_synced_at":"2025-03-11T10:31:45.302Z","repository":{"id":152185668,"uuid":"154517474","full_name":"DerekSelander/lldb_fix","owner":"DerekSelander","description":"RESOLVED IN XCODE 10.2! Fix for LLDB (in Xcode 10) which incorrectly imports the wrong API headers","archived":false,"fork":false,"pushed_at":"2019-02-13T03:30:04.000Z","size":16,"stargazers_count":11,"open_issues_count":0,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-27T13:03:23.142Z","etag":null,"topics":["debugger","debugging","ios","lldb","llvm","macos","simulator","tvos"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DerekSelander.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-24T14:39:51.000Z","updated_at":"2021-03-01T08:29:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"e7ce6f56-3f7a-464f-87bf-ab8783b1dbdf","html_url":"https://github.com/DerekSelander/lldb_fix","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DerekSelander%2Flldb_fix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DerekSelander%2Flldb_fix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DerekSelander%2Flldb_fix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DerekSelander%2Flldb_fix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DerekSelander","download_url":"https://codeload.github.com/DerekSelander/lldb_fix/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243015428,"owners_count":20222080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["debugger","debugging","ios","lldb","llvm","macos","simulator","tvos"],"created_at":"2024-07-29T19:17:08.461Z","updated_at":"2025-03-11T10:31:45.289Z","avatar_url":"https://github.com/DerekSelander.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lldb_fix\n\n## Resolved in Xcode 10.2\n\nThis fix only pertains to Xcode 10.0-10.1, no longer needed in Xcode 10.2\n\n## Huh? \nThis is a fix which patches LLDB v`lldb-1000.11.37.1`, which has a nasty little bug that incorrectly imports the wrong SDK when debugging via a Terminal session. For example, if you were to debug an iOS Simulator application via Terminal, LLDB will import the wrong SDK headers which prevents you from executing code correctly in that process. By default, this version of LLDB will import the MacOSX headers resulting in many scripts breaking in [Facebook's Chisel repository](https://github.com/facebook/chisel) as well as [many of my \"Advanced Debugging and Reverse Engineering\" scripts of my own found here](https://github.com/DerekSelander/LLDB/)\n\nTo see if you affected, open up a Terminal window and check your LLDB version:\n```none\n~$ lldb\n(lldb) version\nlldb-1000.11.37.1\n  Swift-4.2\n(lldb) q\nQuitting LLDB will detach from one or more processes. Do you really want to proceed: [Y/n]  Y\n```\n\nIf you have the same version (or maybe one coming from Xcode 10.1/10.2) this will happen when debugging any iOS Simulator application:\n\n```none\n~$ lldb -n MachOFun #The name of an application on the iOS Simulator that is running\n(lldb) po @import UIKit\nerror: while importing modules:\nerror: Header search couldn't locate module UIKit\n```\n\nThis is because LLDB is looking in the MacOS SDK directory for the UIKit headers. This also means many LLDB scripts which rely on this feature will also fail. For example, check out my [search](https://github.com/DerekSelander/LLDB/blob/master/lldb_commands/search.py) command which enumerates for instances of a class when used against this problematic version of LLDB\n\n```none\n(lldb) search UIViewController    # Enumerates the heap for all alive instances of UIViewController\nerror: \n**************************************\nerror: error: error: unknown type name 'CFMutableSetRef'\nerror: unknown type name 'CFMutableSetRef'\nerror: unknown type name 'CFMutableArrayRef'\nerror: unknown type name 'CFMutableSetRef'\nerror: use of undeclared identifier 'CFMutableSetRef'\nerror: use of undeclared identifier 'CFMutableSetRef'\nerror: use of undeclared identifier 'CFMutableArrayRef'\nerror: 'NSClassFromString' has unknown return type; cast the call to its declared return type\n```\n\nThis is a big problem, since this also cripples a couple chapters in my [Advanced Apple Debugging and Reverse Engineering](https://store.raywenderlich.com/products/advanced-apple-debugging-and-reverse-engineering) :[\n\nThis means that users would need to use a different version of LLDB or find a way to get around this problem...\n\n[You can see a tweet thread about this here](https://twitter.com/LOLgrep/status/1055172805535264768)\n\n## How\n\nThe TLDR: This code will hunt for the location of a problematic c++ function and attempts to overwrite the pointer in a c++ vtable to code I control, correctly setting the SDK type bassed upon the environment variable **LLDB_SDK**\n\nIf no `LLDB_SDK` environment variable is set, the execution will behave normally in the buggy fashion. \n\n### Installation\n\n1) clone/copy repo\n2) cd into repo directory\n3) run `make install`\n\nThis will compile a dylib in the current `$PWD` called lldb_fix.dylib and add the following line of code to `~/.lldbinit`\n\n```\nplugin load $(PWD)/lldb_fix.dylib\n```\n\nLLDB will call this code when it starts executing which performs the lookup of the problematic function and patches it provided you specify a valid `LLDB_SDK` environment variable\n\nYou should make sure the plugin is referenced in ~/.lldbinit with the following command:\n\n```none\ncat ~/.lldbinit | tail -1\n```\n\n### Uninstall\n\n`make clean`\n\n### Just build it without adding to `~/.lldbinit`\n\n`make`\n\n## Usage\n\nThis code will only spring to life provided you have the `LLDB_SDK` environment variable. LLDB_SDK will expect either **sim**, **mac**, or **ios**\n\nSo if you wanted to attach to an application running on the Simulator called MachOFun, then you can do the following:\n\n```\nLLDB_SDK=sim lldb -n MachOFun\n```\n\nYou'll see this plugin is rather chatty... \n\n```\nFound \"AddClangModuleCompilationOptionsForSDKType\" at: 0x1146c1aac\nFound problematic function \"AddClangModuleCompilationOptions\" at: 0x1145c67fe\nFound \"PlatformMacOSX\" vtable c++ class at: 0x115b87c58\nFound problematic function at: PlatformMacOSX`\u003c+0x160\u003e ...patching\nSuccess!\n```\n\nNow try a command that imports a module:\n```\n(lldb) po @import UIKit\nCaught problematic function, changing \"MacOSX\" SDK to \"iPhoneSimulator\"\n```\n\nNo error is a good thing! Now Chisel's and my commands are fair game:\n\n```\n(lldb) search UIViewController\n\u003cBrowserRootViewController: 0x7fc43946ccc0\u003e\n\n\u003cBrowserContainerViewController: 0x7fc43a821200\u003e\n\n\u003cUIInputWindowController: 0x7fc43b077800\u003e\n```\n\nTADA!!!!!!!!!!!!!!!!!!! \n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDerekSelander%2Flldb_fix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDerekSelander%2Flldb_fix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDerekSelander%2Flldb_fix/lists"}