[Lldb-commits] [PATCH] D138407: [LLDB] Add LoongArch register definitions and operations

David Spickett via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Nov 23 04:23:08 PST 2022


DavidSpickett added inline comments.


================
Comment at: lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp:221
+
+  uint8_t *src = const_cast<uint8_t *>(data_sp->GetBytes());
+  if (src == nullptr) {
----------------
seehearfeel wrote:
> DavidSpickett wrote:
> > seehearfeel wrote:
> > > DavidSpickett wrote:
> > > > Possibly not needed const cast.
> > > If no const cast, build failed:
> > > 
> > > ```
> > > /home/loongson/llvm.git/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp:221:12: error: cannot initialize a variable of type 'uint8_t *' (aka 'unsigned char *') with an rvalue of type 'const uint8_t *' (aka 'const unsigned char *')
> > >   uint8_t *src = data_sp->GetBytes();
> > >            ^     ~~~~~~~~~~~~~~~~~~~
> > > 1 error generated.
> > > ```
> > Yes, for the way you've written it that makes sense. But I realise I was looking at the wrong thing here. It's fine that the GetBytes() is const because this is a WriteRegister call, that's expected.
> > 
> > You should be fine using `const uint8_t*` here, because you can still increment that pointer and memcpy from it. Since the pointer itself can change but the data it points to is const.
> > 
> > https://godbolt.org/z/9M9oqr575 might explain it better.
> The correct  code are:
> 
> In ReadAllRegisterValues()
> 
> ```
> uint8_t *dst = data_sp->GetBytes();
> ```
> 
> In WriteAllRegisterValues()
> 
> ```
> const uint8_t *src = data_sp->GetBytes();
> ```
> 
> Thank you.
Yes, exactly!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138407/new/

https://reviews.llvm.org/D138407



More information about the lldb-commits mailing list