[Lldb-commits] [PATCH] D24919: Adding a RegisterContextMinidump_x86_64 converter

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Tue Sep 27 09:28:24 PDT 2016


zturner accepted this revision.
This revision is now accepted and ready to land.

================
Comment at: source/Plugins/Process/minidump/RegisterContextMinidump_x86_64.cpp:50
@@ +49,3 @@
+    size = 8;
+    break;
+  }
----------------
If they are just smaller (but never bigger), you can call `take_front(N)` on the result.  So you could say:

```
writeRegister(source_data, reg_info[lldb_cs_x86_64].mutable_data(result_base).take_front(2));
```

Now the line is starting to get long so might look ugly if it wraps, so it's up to you.  It is somewhat safer at least since you will assert if you accidentally specify an invalid size, and you don't have to worry about getting the computation right.

Perhaps you could combine this with the approach you've already taken here.  Add the functions to `RegisterInfo`, then change `getDestRegister` to look like this:

```
llvm::MutableArrayRef<uint8_t> getDestRegister(const RegisterInfo &reg,
                                               uint8_t *context, uint32_t lldb_reg_num) {
  auto bytes = reg.mutable_data(context);

  switch (lldb_reg_num) {
  case lldb_cs_x86_64:
  case lldb_ds_x86_64:
  case lldb_es_x86_64:
  case lldb_fs_x86_64:
  case lldb_gs_x86_64:
  case lldb_ss_x86_64:
    return bytes.take_front(2);
    break;
  case lldb_rflags_x86_64:
    return bytes.take_front(4);
    break;
  default:
    return bytes.take_front(8);
}
```

then you could call `writeRegister` like this:

```
writeRegister(source_data, getDestRegister(reg_info, result_base, lldb_cs_x86_64));
```

At this point though I'm not sure what's better.  So don't consider this a requirement, up to you :)


https://reviews.llvm.org/D24919





More information about the lldb-commits mailing list