@@ -187,46 +187,32 @@ class RegisterContextDarwin_x86_64_Mach : public RegisterContextDarwin_x86_64 {
187187 SetError (GPRRegSet, Read, -1 );
188188 SetError (FPURegSet, Read, -1 );
189189 SetError (EXCRegSet, Read, -1 );
190- bool done = false ;
191190
192- while (!done ) {
191+ while (offset < data. GetByteSize () ) {
193192 int flavor = data.GetU32 (&offset);
194193 if (flavor == 0 )
195- done = true ;
196- else {
197- uint32_t i;
198- uint32_t count = data.GetU32 (&offset);
199- switch (flavor) {
200- case GPRRegSet:
201- for (i = 0 ; i < count; ++i)
202- (&gpr.rax )[i] = data.GetU64 (&offset);
203- SetError (GPRRegSet, Read, 0 );
204- done = true ;
205-
206- break ;
207- case FPURegSet:
208- // TODO: fill in FPU regs....
209- // SetError (FPURegSet, Read, -1);
210- done = true ;
211-
212- break ;
213- case EXCRegSet:
214- exc.trapno = data.GetU32 (&offset);
215- exc.err = data.GetU32 (&offset);
216- exc.faultvaddr = data.GetU64 (&offset);
217- SetError (EXCRegSet, Read, 0 );
218- done = true ;
219- break ;
220- case 7 :
221- case 8 :
222- case 9 :
223- // fancy flavors that encapsulate of the above flavors...
224- break ;
225-
226- default :
227- done = true ;
228- break ;
229- }
194+ break ;
195+ uint32_t count = data.GetU32 (&offset);
196+ switch (flavor) {
197+ case GPRRegSet: {
198+ uint32_t *gpr_data = reinterpret_cast <uint32_t *>(&gpr.rax );
199+ for (uint32_t i = 0 ; i < count && offset < data.GetByteSize (); ++i)
200+ gpr_data[i] = data.GetU32 (&offset);
201+ SetError (GPRRegSet, Read, 0 );
202+ } break ;
203+ case FPURegSet:
204+ // TODO: fill in FPU regs....
205+ SetError (FPURegSet, Read, -1 );
206+ break ;
207+ case EXCRegSet:
208+ exc.trapno = data.GetU32 (&offset);
209+ exc.err = data.GetU32 (&offset);
210+ exc.faultvaddr = data.GetU64 (&offset);
211+ SetError (EXCRegSet, Read, 0 );
212+ break ;
213+ default :
214+ offset += count * 4 ;
215+ break ;
230216 }
231217 }
232218 }
@@ -356,11 +342,11 @@ class RegisterContextDarwin_x86_64_Mach : public RegisterContextDarwin_x86_64 {
356342 }
357343
358344protected:
359- int DoReadGPR (lldb::tid_t tid, int flavor, GPR &gpr) override { return 0 ; }
345+ int DoReadGPR (lldb::tid_t tid, int flavor, GPR &gpr) override { return - 1 ; }
360346
361- int DoReadFPU (lldb::tid_t tid, int flavor, FPU &fpu) override { return 0 ; }
347+ int DoReadFPU (lldb::tid_t tid, int flavor, FPU &fpu) override { return - 1 ; }
362348
363- int DoReadEXC (lldb::tid_t tid, int flavor, EXC &exc) override { return 0 ; }
349+ int DoReadEXC (lldb::tid_t tid, int flavor, EXC &exc) override { return - 1 ; }
364350
365351 int DoWriteGPR (lldb::tid_t tid, int flavor, const GPR &gpr) override {
366352 return 0 ;
@@ -5893,27 +5879,8 @@ bool ObjectFileMachO::GetCorefileThreadExtraInfos(
58935879 std::lock_guard<std::recursive_mutex> guard (module_sp->GetMutex ());
58945880
58955881 Log *log (GetLog (LLDBLog::Object | LLDBLog::Process | LLDBLog::Thread));
5896- auto lc_notes = FindLC_NOTEByName (" process metadata" );
5897- for (auto lc_note : lc_notes) {
5898- offset_t payload_offset = std::get<0 >(lc_note);
5899- offset_t strsize = std::get<1 >(lc_note);
5900- std::string buf (strsize, ' \0 ' );
5901- if (m_data.CopyData (payload_offset, strsize, buf.data ()) != strsize) {
5902- LLDB_LOGF (log,
5903- " Unable to read %" PRIu64
5904- " bytes of 'process metadata' LC_NOTE JSON contents" ,
5905- strsize);
5906- return false ;
5907- }
5908- while (buf.back () == ' \0 ' )
5909- buf.resize (buf.size () - 1 );
5910- StructuredData::ObjectSP object_sp = StructuredData::ParseJSON (buf);
5882+ if (StructuredData::ObjectSP object_sp = GetCorefileProcessMetadata ()) {
59115883 StructuredData::Dictionary *dict = object_sp->GetAsDictionary ();
5912- if (!dict) {
5913- LLDB_LOGF (log, " Unable to read 'process metadata' LC_NOTE, did not "
5914- " get a dictionary." );
5915- return false ;
5916- }
59175884 StructuredData::Array *threads;
59185885 if (!dict->GetValueForKeyAsArray (" threads" , threads) || !threads) {
59195886 LLDB_LOGF (log,
@@ -5956,6 +5923,49 @@ bool ObjectFileMachO::GetCorefileThreadExtraInfos(
59565923 return false ;
59575924}
59585925
5926+ StructuredData::ObjectSP ObjectFileMachO::GetCorefileProcessMetadata () {
5927+ ModuleSP module_sp (GetModule ());
5928+ if (!module_sp)
5929+ return {};
5930+
5931+ Log *log (GetLog (LLDBLog::Object | LLDBLog::Process | LLDBLog::Thread));
5932+ std::lock_guard<std::recursive_mutex> guard (module_sp->GetMutex ());
5933+ auto lc_notes = FindLC_NOTEByName (" process metadata" );
5934+ if (lc_notes.size () == 0 )
5935+ return {};
5936+
5937+ if (lc_notes.size () > 1 )
5938+ LLDB_LOGF (
5939+ log,
5940+ " Multiple 'process metadata' LC_NOTEs found, only using the first." );
5941+
5942+ auto [payload_offset, strsize] = lc_notes[0 ];
5943+ std::string buf (strsize, ' \0 ' );
5944+ if (m_data.CopyData (payload_offset, strsize, buf.data ()) != strsize) {
5945+ LLDB_LOGF (log,
5946+ " Unable to read %" PRIu64
5947+ " bytes of 'process metadata' LC_NOTE JSON contents" ,
5948+ strsize);
5949+ return {};
5950+ }
5951+ while (buf.back () == ' \0 ' )
5952+ buf.resize (buf.size () - 1 );
5953+ StructuredData::ObjectSP object_sp = StructuredData::ParseJSON (buf);
5954+ if (!object_sp) {
5955+ LLDB_LOGF (log, " Unable to read 'process metadata' LC_NOTE, did not "
5956+ " parse as valid JSON." );
5957+ return {};
5958+ }
5959+ StructuredData::Dictionary *dict = object_sp->GetAsDictionary ();
5960+ if (!dict) {
5961+ LLDB_LOGF (log, " Unable to read 'process metadata' LC_NOTE, did not "
5962+ " get a dictionary." );
5963+ return {};
5964+ }
5965+
5966+ return object_sp;
5967+ }
5968+
59595969lldb::RegisterContextSP
59605970ObjectFileMachO::GetThreadContextAtIndex (uint32_t idx,
59615971 lldb_private::Thread &thread) {
0 commit comments