================
@@ -0,0 +1,107 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the definition of the RegisterContextFreeBSDKernel_arm
+/// class, which is used for reading registers from PCB on arm kernel dump.
+///
+//===----------------------------------------------------------------------===//
+
+#include "RegisterContextFreeBSDKernel_arm.h"
+#include "Plugins/Process/Utility/lldb-arm-register-enums.h"
+
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Utility/RegisterValue.h"
+#include "llvm/Support/Endian.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+RegisterContextFreeBSDKernel_arm::RegisterContextFreeBSDKernel_arm(
+ Thread &thread, std::unique_ptr<RegisterInfoPOSIX_arm> register_info_up,
+ lldb::addr_t pcb_addr)
+ : RegisterContextPOSIX_arm(thread, std::move(register_info_up)),
+ m_pcb_addr(pcb_addr) {}
+
+bool RegisterContextFreeBSDKernel_arm::ReadGPR() { return true; }
+
+bool RegisterContextFreeBSDKernel_arm::ReadFPR() { return true; }
+
+bool RegisterContextFreeBSDKernel_arm::WriteGPR() {
+ assert(0);
+ return false;
+}
+
+bool RegisterContextFreeBSDKernel_arm::WriteFPR() {
+ assert(0);
+ return false;
+}
+
+bool RegisterContextFreeBSDKernel_arm::ReadRegister(
+ const RegisterInfo *reg_info, RegisterValue &value) {
+ if (m_pcb_addr == LLDB_INVALID_ADDRESS)
+ return false;
+
+ // https://cgit.freebsd.org/src/tree/sys/arm/include/frame.h
+ // struct pcb's first field is struct switchframe which is the only field
used
+ // by debugger and should be aligned by 8 bytes.
+ struct {
+ llvm::support::ulittle32_t r4;
+ llvm::support::ulittle32_t r5;
+ llvm::support::ulittle32_t r6;
+ llvm::support::ulittle32_t r7;
+ llvm::support::ulittle32_t r8;
+ llvm::support::ulittle32_t r9;
+ llvm::support::ulittle32_t r10;
+ llvm::support::ulittle64_t r11;
+ llvm::support::ulittle64_t r12;
+ llvm::support::ulittle64_t sp;
+ llvm::support::ulittle64_t lr;
+ llvm::support::ulittle64_t pc;
+ } pcb;
----------------
DavidSpickett wrote:
Right but in those cases, the pcb seems to be:
```
struct pcb {
type field_a;
type field_b;
...
}
```
Whereas here the first entry in the pcb is another struct. Which confuses me
because I read your comment:
```
// https://cgit.freebsd.org/src/tree/sys/arm/include/frame.h
// struct pcb's first field is struct switchframe which is the only field used
// by debugger and should be aligned by 8 bytes.
```
Which tells me that only switchframe is used by the debugger.
Then you declare a struct that is called pcb. So which is it, are you using the
pcb or the switchframe?
Yes I can stare at it for a bit longer and figure it out, but ideally we don't
make people do that or at least we help them do it faster when it's cheap to do
so.
If you don't want to change the name that's fair enough, the inner struct is a
detail that this code doesn't need to care about. So how about:
```
struct {
llvm::support::ulittle32_t r4; // Aka switchframe.sf_r4.
llvm::support::ulittle32_t r5;
llvm::support::ulittle32_t r6;
llvm::support::ulittle32_t r7;
llvm::support::ulittle32_t r8;
llvm::support::ulittle32_t r9;
llvm::support::ulittle32_t r10;
llvm::support::ulittle32_t r11;
llvm::support::ulittle32_t r12;
llvm::support::ulittle32_t sp;
llvm::support::ulittle32_t lr;
llvm::support::ulittle32_t pc;
// switchframe.sf_tpidrurw is unused.
// switchframe.sf_spare0 unused.
} pcb;
```
Then the reader immediately realises oh, even though it's declared as
pcb.switchframe in FreeBSD, this flattened pcb definition is the equivalent
layout.
https://github.com/llvm/llvm-project/pull/180674
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits