@@ -187,46 +187,32 @@ class RegisterContextDarwin_x86_64_Mach : public RegisterContextDarwin_x86_64 {
187
187
SetError (GPRRegSet, Read, -1 );
188
188
SetError (FPURegSet, Read, -1 );
189
189
SetError (EXCRegSet, Read, -1 );
190
- bool done = false ;
191
190
192
- while (!done ) {
191
+ while (offset < data. GetByteSize () ) {
193
192
int flavor = data.GetU32 (&offset);
194
193
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 ;
230
216
}
231
217
}
232
218
}
@@ -356,11 +342,11 @@ class RegisterContextDarwin_x86_64_Mach : public RegisterContextDarwin_x86_64 {
356
342
}
357
343
358
344
protected:
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 ; }
360
346
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 ; }
362
348
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 ; }
364
350
365
351
int DoWriteGPR (lldb::tid_t tid, int flavor, const GPR &gpr) override {
366
352
return 0 ;
@@ -5893,27 +5879,8 @@ bool ObjectFileMachO::GetCorefileThreadExtraInfos(
5893
5879
std::lock_guard<std::recursive_mutex> guard (module_sp->GetMutex ());
5894
5880
5895
5881
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 ()) {
5911
5883
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
- }
5917
5884
StructuredData::Array *threads;
5918
5885
if (!dict->GetValueForKeyAsArray (" threads" , threads) || !threads) {
5919
5886
LLDB_LOGF (log,
@@ -5956,6 +5923,49 @@ bool ObjectFileMachO::GetCorefileThreadExtraInfos(
5956
5923
return false ;
5957
5924
}
5958
5925
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
+
5959
5969
lldb::RegisterContextSP
5960
5970
ObjectFileMachO::GetThreadContextAtIndex (uint32_t idx,
5961
5971
lldb_private::Thread &thread) {
0 commit comments