[Dwarf-Discuss] dwarf stack operator for byte swap.
Chirag Patel
Chirag@raincode.com
Mon Nov 11 07:37:19 GMT 2019
Hello Michael,
Thanks for the confirmation. Kindly inform me if anything needs to be updated from myside.
Regards,
Chirag Patel
Software Engineer | Raincode Labs India
Tel: (+91) 080 41159811
Mob: (+91) 9049336744
www.raincodelabs.com
-----Original Message-----
From: Michael Eager <eager@eagercon.com>
Sent: 08 November 2019 20:04
To: Chirag Patel <Chirag at raincode.com>; Robinson, Paul <paul.robinson at sony.com>; Ron Brender <ron.brender at gmail.com>
Cc: dwarf-discuss at lists.dwarfstd.org
Subject: Re: [Dwarf-Discuss] dwarf stack operator for byte swap.
Hi Chirag --
Thanks for your submission. It was received.
I'm redesigning the DWARF website, in part to address the problem that it receives a lot of spam submissions. Your issue will be posted soon.
On 11/7/19 10:51 PM, Chirag Patel wrote:
> Hi all,
>
> I have sent a comment through http://dwarfstd.org/Comment.php
>
> But below is the body of the comment "
>
> Section 2.5.1.7, pg 37
>
> DW_OP_byte_swap to Byte Swap the data on top of the dwarf stack.
>
> ======================================================================
> =========
>
> Overview
>
> ------------
>
> For debugging binary with bi-endian marked dwarf DIEs and the some
> calculation
>
> depending at runtime, the data needs to be loaded at runtime and needs
> to be
>
> byte swapped. the depended variable DIE here is marked as big-endian
> and the
>
> host is little-endian. The DW_OP_byte_swap will byte swap the raw data
> stored
>
> in top dwarf stack entry.
>
> .
>
> 0x00000057:?? DW_TAG_variable
>
> ??????????????? DW_AT_name????? ("__gbloffset__")
>
> ??????????????? DW_AT_type????? (0x000001e5 "int")
>
> ??????????????? DW_AT_external? (true)
>
> ??????????????? DW_AT_decl_file (".")
>
> ??????????????? DW_AT_decl_line (8)
>
> ??????????????? DW_AT_location? (DW_OP_addr 0) // pre linkage
>
> ??????????????? DW_AT_linkage_name????? ("_gblsection__")
>
> ??????????????? DW_AT_endianity (DW_END_big)
>
> 0x00000170:?? DW_TAG_variable
>
> ??????????????? DW_AT_name????? ("VAR1")
>
> ??????????????? DW_AT_type????? (0x0000010b "fixed.dec.display.72")
>
> ??????????????? DW_AT_decl_file (".")
>
> ??????????????? DW_AT_decl_line (10)
>
> ??????????????? DW_AT_location? (DW_OP_addr 0x0, DW_OP_call4 0x57,
> DW_OP_deref_size, 4,
>
> DW_OP_dup, DW_OP_constu 0xff, DW_OP_lit0, DW_OP_shl, DW_OP_and,
> DW_OP_lit24, DW_OP_shl, DW_OP_swap, DW_OP_dup, DW_OP_constu 0xff,
> DW_OP_lit8, DW_OP_shl, DW_OP_and, DW_OP_lit8, DW_OP_shl, DW_OP_swap,
> DW_OP_dup, DW_OP_constu 0xff, DW_OP_lit16, DW_OP_shl, DW_OP_and,
> DW_OP_lit8, DW_OP_shr, DW_OP_swap, DW_OP_constu 0xff, DW_OP_lit24,
> DW_OP_shl, DW_OP_and, DW_OP_lit24, DW_OP_shr, DW_OP_swap, DW_OP_or,
> DW_OP_or, DW_OP_or, DW_OP_plus)
>
> ??????????????? DW_AT_linkage_name????? ("VAR1")
>
> In above snippet, the DW_OP_byte_swap will replace,
>
> DW_OP_dup, DW_OP_constu 0xff, DW_OP_lit0, DW_OP_shl, DW_OP_and,
> DW_OP_lit24, DW_OP_shl, DW_OP_swap, DW_OP_dup, DW_OP_constu 0xff,
> DW_OP_lit8, DW_OP_shl, DW_OP_and, DW_OP_lit8, DW_OP_shl, DW_OP_swap,
> DW_OP_dup, DW_OP_constu 0xff, DW_OP_lit16, DW_OP_shl, DW_OP_and,
> DW_OP_lit8, DW_OP_shr, DW_OP_swap, DW_OP_constu 0xff, DW_OP_lit24,
> DW_OP_shl, DW_OP_and, DW_OP_lit24, DW_OP_shr, DW_OP_swap, DW_OP_or,
> DW_OP_or, DW_OP_or number of operations.
>
> Proposed changes to DWARF
>
> ---------------------------
>
> 2.5.1.7 Special Operation
>
> Addition
>
> <n> DW_OP_byte_swap
>
> ?????????????? The DW_OP_byte_swap operation pops the top stack
> entry, byte swaps the value
>
> ?????????????? and pushes back the swapped value on the dwarf stack.
>
> ?????????????? e.g. so 0x12345678 will become 0x78563412, useful to
> change endianity of raw
>
> ?????????????? data.
>
> ---------------------------
>
> "
>
> i did not received any confirmation on my mail. How can I check if it
> was sent correctly?
>
> Kindly inform me if anything more needs to be done from myside.
>
> Regards,
>
> **
>
> *Chirag Patel*
>
> Software Engineer | Raincode Labs India
>
> *Tel*: (+91) 080 41159811
>
> *Mob*: (+91) 9049336744
>
> _www.raincodelabs.com <http://www.raincodelabs.com/>_
>
> linkedin-button <https://in.linkedin.com/in/chirag-patel->
>
> *From:*Chirag Patel <Chirag at raincode.com>
> *Sent:* 29 October 2019 17:10
> *To:* Michael Eager <eager at eagercon.com>; Robinson, Paul
> <paul.robinson at sony.com>; Ron Brender <ron.brender at gmail.com>
> *Cc:* dwarf-discuss at lists.dwarfstd.org
> *Subject:* Re: [Dwarf-Discuss] dwarf stack operator for byte swap.
>
> Hello,
>
> Thank you all for prompt reply.
>
> @Robinson, Paul <mailto:paul.robinson at sony.com>,
>
> Thanks for the shorter list of operators, but as Michael has
> suggested, i have added a vendor specific operator for that in
> llvm/lldb(fork of our branch anyways).
>
> the operator, pops the stack entry and byte reverses the value and
> pushes it back on the stack.
>
> @Ron Brender <mailto:ron.brender at gmail.com>
>
> The operator that i was suggesting, pops the top of the stack,
> reverses the bytes and pushes it on the stack(like neg operator does
> for negation).(on second thought the byte_rev would be a better name)
>
> About the other cases you suggested, i sure hope others can help to
> zero in for perfect
>
> design to cover wide range.
>
> @Michael Eager <mailto:eager at eagercon.com>
>
> Thanks, i have tried the same for our fork of llvm/lldb branch and it
> seems to be working well(for our case :).
> https://gitlab.phidani.be/Chirag.Patel
>
> Thank you all for the helpful comments. i will open a dwarf
> enhancement request soon.
>
> Best Regards.
>
> *Chirag Patel*
>
> Software Engineer*| *Raincode Labs India
>
> Tel: (+91) 080 41159811
>
> Mob: (+91) 9049336744
>
> <https://www.linkedin.com/in/chirag-patel-/>
>
> _
>
> <https://www.linkedin.com/in/chirag-patel-/>_
>
> <https://www.linkedin.com/in/chirag-patel-/>
>
> ----------------------------------------------------------------------
> --
>
> *From:*Michael Eager <eager at eagercon.com <mailto:eager at eagercon.com>>
> *Sent:* 28 October 2019 20:37
> *To:* Robinson, Paul <paul.robinson at sony.com
> <mailto:paul.robinson at sony.com>>; Chirag Patel <Chirag at raincode.com
> <mailto:Chirag at raincode.com>>
> *Cc:* dwarf-discuss at lists.dwarfstd.org
> <mailto:dwarf-discuss at lists.dwarfstd.org>
> <dwarf-discuss at lists.dwarfstd.org
> <mailto:dwarf-discuss at lists.dwarfstd.org>>
> *Subject:* Re: [Dwarf-Discuss] dwarf stack operator for byte swap.
>
> Hi Chirag --
>
> A byte-swap operator would be a reasonable addition to the DWARF
> interpreter.
>
> In addition to writing a proposal as Paul suggests, one option I would
> recommend you consider is to create a user-defined operation to
> perform this byte-swap operation and give it a value in the range
> between DW_OP_lo_user and DW_OP_hi_user.? Of course, this user-defined
> would need to be implemented not only in the producer (i.e., compiler)
> but in any consumers (i.e., debugger).
>
> When a new version of the DWARF Standard is released, this operation
> would be assigned a new value.
>
> On 10/28/19 6:53 AM, Robinson, Paul via Dwarf-Discuss wrote:
> > Hello Chirag,
> >
> > Regarding a byte-swap operation, it seems that you have a
> reasonable > use-case on a bi-endian machine.? Feel free to request a
> new operator on > the "public comments" page at
> http://dwarfstd.org/Comment.php > > Note that a byte-swap operator
> would swap all bytes in the top-of-stack > value, which on your
> 64-bit machine would of course be a 64-bit value.
> > As you want a 32-bit swapped value, you would still need to do a
> shift > afterward, but even so, "DW_OP_byte_swap DW_OP_const1u 32 DW_OP_shr"
> > would be considerably shorter than what you have to do now.
> >
> > Of course a new operator would be introduced in a new DWARF
> revision, > which is likely to be years away.? In the meantime let me
> suggest a > shorter expression for doing the byte-swap operation.?
> The book > "Hacker's Delight" shows a straightforward 32-bit byte
> swap with masks > no wider than 16 bits, as follows:
> >
> >? ?????????????? x = (x << 24) | ((x & 0xff00) << 8) | ((x >> 8) &
> > 0xff00) | (x >> 24); > > Your 64-bit machine will of course use
> 64-bit values on the expression > stack, so to keep the result
> "32-bit clean" we want to do one additional > mask:
> >
> >? ?????????????? x = ((x & 0xff) << 24) | ((x & 0xff00) << 8) | ((x
> >> 8) > & 0xff00) | (x >> 24); > > Translating this into a DWARF
> expression, I get the following:
> >
> >? ?????????????? DW_OP_dup, DW_OP_const1u 0xff, DW_OP_and,
> DW_OP_lit24, > DW_OP_shl, DW_OP_swap, DW_OP_dup, DW_OP_const2u
> 0xff00, DW_OP_and, > DW_OP_lit8, DW_OP_shl, DW_OP_swap, DW_OP_dup,
> DW_OP_lit8, DW_OP_shr, > DW_OP_const2u 0xff00, DW_OP_and, DW_OP_swap,
> DW_OP_lit24, DW_OP_shr, > DW_OP_or, DW_OP_or, DW_OP_or > > I hope
> this is helpful to you.
> >
> > --paulr
> >
> > *From:* Dwarf-Discuss <dwarf-discuss-bounces at lists.dwarfstd.org
> <mailto:dwarf-discuss-bounces at lists.dwarfstd.org>> *On > Behalf Of
> *Chirag Patel via Dwarf-Discuss > *Sent:* Monday, October 28, 2019
> 12:47 AM > *To:* dwarf-discuss at lists.dwarfstd.org
> <mailto:dwarf-discuss at lists.dwarfstd.org>
> > *Subject:* [Dwarf-Discuss] dwarf stack operator for byte swap.
> >
> > Hello Dwarf experts.
> >
> > I am currently working trying to encode dwarf of binaries with
> having > bi-endian variables marked with DW_AT_endianity attribute.
> >
> > The location calculation for some? variable depends on other
> variable > with different endianity, also the value of this other
> variable is known > at runtime.
> >
> > At the moment I am using location list to calculate the correct
> location > of first variable and list of dwarf operators to reverse
> the endianity > of variable "__gbloffset__" in below case (I only
> needed lower 32 bits > on 64 bit machine).
> >
> > 0x000001e5: DW_TAG_base_type
> >
> >? ?DW_AT_byte_size ?(0x04)
> >
> >? ? DW_AT_encoding? (DW_ATE_signed)
> >
> >? ??????????????? DW_AT_name????? ("int") > >? ???????????????
> DW_AT_endianity (DW_END_big) > > . > > 0x00000057:??
> DW_TAG_variable > >? ??????????????? DW_AT_name?????
> ("__gbloffset__") > >? ??????????????? DW_AT_type????? (0x000001e5
> "int") > >? ??????????????? DW_AT_external? (true) > >? ???????????????
> DW_AT_decl_file (".") > >? ??????????????? DW_AT_decl_line (8) > >? ??????????? ????
> DW_AT_location? (DW_OP_addr 0) // pre linkage > >? ???????????????
> DW_AT_linkage_name????? ("_gblsection__") > > 0x00000170:??
> DW_TAG_variable > >? ??????????????? DW_AT_name????? ("VAR1") > >? ???????????????
> DW_AT_type????? (0x0000010b "fixed.dec.display.72") > >? ????????? ??????
> DW_AT_decl_file (".") > >? ??????????????? DW_AT_decl_line (10) >
> >? ??????????????? DW_AT_location? (DW_OP_addr 0x0, DW_OP_call4 0x57,
> > DW_OP_deref_size, 4, > > DW_OP_dup, DW_OP_constu 0xff, DW_OP_lit0,
> DW_OP_shl, DW_OP_and, > DW_OP_lit24, DW_OP_shl, DW_OP_swap,
> DW_OP_dup, DW_OP_constu 0xff, > DW_OP_lit8, DW_OP_shl, DW_OP_and,
> DW_OP_lit8, DW_OP_shl, DW_OP_swap, > DW_OP_dup, DW_OP_constu 0xff,
> DW_OP_lit16, DW_OP_shl, DW_OP_and, > DW_OP_lit8, DW_OP_shr,
> DW_OP_swap, DW_OP_constu 0xff, DW_OP_lit24, > DW_OP_shl, DW_OP_and,
> DW_OP_lit24, DW_OP_shr, DW_OP_swap, DW_OP_or, > DW_OP_or, DW_OP_or,
> DW_OP_plus) > >? ??????????????? DW_AT_linkage_name????? ("VAR1") >
> > In above snippet of dwarf dump, I am using yellow highlighted list
> of > operators to swap the bytes.
> >
> > I think there should be a support for DW_OP_byte_swap simple
> operator to > accomplice this simple task. Does this idea looks like it can be useful?
> > Is there any specific reason why dwarf spec does not have it or I
> am > missing something subtle.
> >
> > I hope I conveyed the idea properly, apologies in advanced as
> English is > not my first language.
> >
> > **
> >
> > *Thanks and regards,*
> >
> > **
> >
> > *Chirag Patel*
> >
> > Software Engineer | Raincode Labs India > > *Tel*: (+91) 080
> 41159811 > > *Mob*: (+91) 9049336744 > > www.raincodelabs.com
> <http://www.raincodelabs.com> <http://www.raincodelabs.com/>__ > >
> linkedin-button <https://in.linkedin.com/in/chirag-patel->
> >
> >
> > _______________________________________________
> > Dwarf-Discuss mailing list
> > Dwarf-Discuss at lists.dwarfstd.org
> <mailto:Dwarf-Discuss at lists.dwarfstd.org>
> > http://lists.dwarfstd.org/listinfo.cgi/dwarf-discuss-dwarfstd.org
> >
>
> --
> Michael Eager eager at eagercon.com <mailto:eager at eagercon.com>
> 1960 Park Blvd., Palo Alto, CA 94306
>
--
Michael Eager eager at eagercon.com
1960 Park Blvd., Palo Alto, CA 94306
More information about the Dwarf-discuss
mailing list