[lldb-dev] [PATCH] 32-bit linux use hard-coded DR0 offset not offsetof against a structure

Matthew Gardiner mg11 at csr.com
Tue Mar 4 02:22:23 PST 2014

Hi folks

I'm posting this to dev not commits as it's slightly contentious, but when
combined with an earlier posting of mine:

[Lldb-commits] [PATCH] 32-bit linux Remove WriteRegOperation's explicit GetAsUInt32() call

this proposal fixes the 32-bit linux debug experience.

This patch proposes to calculate the offset of an i386 debug offset using a
simple base + multiple sum, instead using offsetof against a structure.

We all know that there are lots of ways to solve this problem. I'm posting this
one as it is compact and fits with the existing "#define DR_OFFSET(reg_index)"

Index: source/Plugins/Process/POSIX/RegisterContextLinux_i386.cpp
--- source/Plugins/Process/POSIX/RegisterContextLinux_i386.cpp	(revision 202806)
+++ source/Plugins/Process/POSIX/RegisterContextLinux_i386.cpp	(working copy)
@@ -83,8 +83,9 @@

  #define DR_SIZE sizeof(UserArea::u_debugreg[0])
+#define DR_0_OFFSET 0xFC
  #define DR_OFFSET(reg_index) \
-    (LLVM_EXTENSION offsetof(UserArea, u_debugreg[reg_index]))
+    (DR_0_OFFSET + (reg_index * 4))
  #define FPR_SIZE(reg) sizeof(((FPR_i386*)NULL)->reg)


Using the offsetof(struct, element) mantra can be problematic, if the underlying
structure is changed, and has no benefits IMO if the structure is not also used
as a structure.

Could someone apply this or a similar patch?


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Keep up to date with CSR on our technical blog, www.csr.com/blog, CSR people blog, www.csr.com/people, YouTube, www.youtube.com/user/CSRplc, Facebook, www.facebook.com/pages/CSR/191038434253534, or follow us on Twitter at www.twitter.com/CSR_plc.
New for 2014, you can now access the wide range of products powered by aptX at www.aptx.com.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: RegisterContextLinux_i386.cpp.diff
Type: text/x-patch
Size: 660 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20140304/9a8330a3/attachment.bin>

More information about the lldb-dev mailing list