-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[lldb][Mach-O] Allow "process metadata" LC_NOTE to supply registers #144627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
92348b2
6f57048
1ddbda4
ce289ab
1c8819d
0721824
3a0a555
89317d8
7c2bfc6
dbc414b
2a41c88
eecd470
3c69582
be740fe
cae9dac
eac8d49
cdd6f1d
c29ffe6
8213628
6da9489
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5794,27 +5794,8 @@ bool ObjectFileMachO::GetCorefileThreadExtraInfos( | |
| std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); | ||
|
|
||
| Log *log(GetLog(LLDBLog::Object | LLDBLog::Process | LLDBLog::Thread)); | ||
| auto lc_notes = FindLC_NOTEByName("process metadata"); | ||
| for (auto lc_note : lc_notes) { | ||
| offset_t payload_offset = std::get<0>(lc_note); | ||
| offset_t strsize = std::get<1>(lc_note); | ||
| std::string buf(strsize, '\0'); | ||
| if (m_data.CopyData(payload_offset, strsize, buf.data()) != strsize) { | ||
| LLDB_LOGF(log, | ||
| "Unable to read %" PRIu64 | ||
| " bytes of 'process metadata' LC_NOTE JSON contents", | ||
| strsize); | ||
| return false; | ||
| } | ||
| while (buf.back() == '\0') | ||
| buf.resize(buf.size() - 1); | ||
| StructuredData::ObjectSP object_sp = StructuredData::ParseJSON(buf); | ||
| if (StructuredData::ObjectSP object_sp = GetCorefileProcessMetadata()) { | ||
| StructuredData::Dictionary *dict = object_sp->GetAsDictionary(); | ||
| if (!dict) { | ||
| LLDB_LOGF(log, "Unable to read 'process metadata' LC_NOTE, did not " | ||
| "get a dictionary."); | ||
| return false; | ||
| } | ||
| StructuredData::Array *threads; | ||
| if (!dict->GetValueForKeyAsArray("threads", threads) || !threads) { | ||
| LLDB_LOGF(log, | ||
|
|
@@ -5857,6 +5838,50 @@ bool ObjectFileMachO::GetCorefileThreadExtraInfos( | |
| return false; | ||
| } | ||
|
|
||
| StructuredData::ObjectSP ObjectFileMachO::GetCorefileProcessMetadata() { | ||
| ModuleSP module_sp(GetModule()); | ||
| if (!module_sp) | ||
| return {}; | ||
|
|
||
| Log *log(GetLog(LLDBLog::Object | LLDBLog::Process | LLDBLog::Thread)); | ||
| std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); | ||
| auto lc_notes = FindLC_NOTEByName("process metadata"); | ||
| if (lc_notes.size() == 0) | ||
| return {}; | ||
|
|
||
| if (lc_notes.size() > 1) | ||
| LLDB_LOGF( | ||
| log, | ||
| "Multiple 'process metadata' LC_NOTEs found, only using the first."); | ||
|
|
||
| offset_t payload_offset = std::get<0>(lc_notes[0]); | ||
| offset_t strsize = std::get<1>(lc_notes[0]); | ||
| std::string buf(strsize, '\0'); | ||
| if (m_data.CopyData(payload_offset, strsize, buf.data()) != strsize) { | ||
| LLDB_LOGF(log, | ||
| "Unable to read %" PRIu64 | ||
| " bytes of 'process metadata' LC_NOTE JSON contents", | ||
| strsize); | ||
| return {}; | ||
| } | ||
| while (buf.back() == '\0') | ||
| buf.resize(buf.size() - 1); | ||
| StructuredData::ObjectSP object_sp = StructuredData::ParseJSON(buf); | ||
| if (!object_sp) { | ||
| LLDB_LOGF(log, "Unable to read 'process metadata' LC_NOTE, did not " | ||
| "parse as valid JSON."); | ||
|
Comment on lines
+5870
to
+5871
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to change anything, but another way to handle this is to make this function return an |
||
| return {}; | ||
| } | ||
| StructuredData::Dictionary *dict = object_sp->GetAsDictionary(); | ||
| if (!dict) { | ||
| LLDB_LOGF(log, "Unable to read 'process metadata' LC_NOTE, did not " | ||
| "get a dictionary."); | ||
| return {}; | ||
| } | ||
|
|
||
| return object_sp; | ||
| } | ||
|
|
||
| lldb::RegisterContextSP | ||
| ObjectFileMachO::GetThreadContextAtIndex(uint32_t idx, | ||
| lldb_private::Thread &thread) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.