From 85b453c2e4301dcabd76074191a27e41d1681e04 Mon Sep 17 00:00:00 2001 From: Liav A Date: Tue, 4 Oct 2022 05:39:57 +0300 Subject: [PATCH] Kernel+Userland: Remove dependency on i386-specific registers --- Kernel/Arch/x86/RegisterState.h | 2 +- Kernel/ThreadTracer.h | 2 +- ...ic-ptrace-based-native-target-for-Se.patch | 2 +- Userland/Applications/Debugger/main.cpp | 2 +- .../HackStudio/Debugger/BacktraceModel.h | 2 +- .../HackStudio/Debugger/DebugInfoWidget.h | 2 +- .../HackStudio/Debugger/DisassemblyModel.h | 2 +- .../HackStudio/Debugger/DisassemblyWidget.h | 2 +- .../HackStudio/Debugger/RegistersModel.h | 2 +- .../HackStudio/Debugger/VariablesModel.h | 2 +- .../Libraries/LibC/sys/arch/x86_64/regs.h | 137 ++++-------------- Userland/Libraries/LibDebug/DebugInfo.h | 2 +- Userland/Libraries/LibDebug/DebugSession.h | 2 +- .../Libraries/LibDebug/Dwarf/Expression.cpp | 2 +- .../Libraries/LibDebug/ProcessInspector.h | 2 +- Userland/Libraries/LibELF/Core.h | 2 +- Userland/Utilities/functrace.cpp | 2 +- Userland/Utilities/strace.cpp | 2 +- 18 files changed, 47 insertions(+), 124 deletions(-) diff --git a/Kernel/Arch/x86/RegisterState.h b/Kernel/Arch/x86/RegisterState.h index b69315c547..65e6b059a4 100644 --- a/Kernel/Arch/x86/RegisterState.h +++ b/Kernel/Arch/x86/RegisterState.h @@ -7,7 +7,7 @@ #pragma once #include -#include +#include #include #include diff --git a/Kernel/ThreadTracer.h b/Kernel/ThreadTracer.h index 29b1ef1e60..892cda9046 100644 --- a/Kernel/ThreadTracer.h +++ b/Kernel/ThreadTracer.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include namespace Kernel { diff --git a/Ports/gdb/patches/0002-serenity-Add-basic-ptrace-based-native-target-for-Se.patch b/Ports/gdb/patches/0002-serenity-Add-basic-ptrace-based-native-target-for-Se.patch index 129319d8df..abe6a9112b 100644 --- a/Ports/gdb/patches/0002-serenity-Add-basic-ptrace-based-native-target-for-Se.patch +++ b/Ports/gdb/patches/0002-serenity-Add-basic-ptrace-based-native-target-for-Se.patch @@ -129,7 +129,7 @@ index 0000000..034252a +#include "regset.h" +#include "target.h" + -+#include ++#include +#include + +#include "i386-tdep.h" diff --git a/Userland/Applications/Debugger/main.cpp b/Userland/Applications/Debugger/main.cpp index eab199ca95..1eba7028ad 100644 --- a/Userland/Applications/Debugger/main.cpp +++ b/Userland/Applications/Debugger/main.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Userland/DevTools/HackStudio/Debugger/BacktraceModel.h b/Userland/DevTools/HackStudio/Debugger/BacktraceModel.h index 43df6afbb0..7090d28f09 100644 --- a/Userland/DevTools/HackStudio/Debugger/BacktraceModel.h +++ b/Userland/DevTools/HackStudio/Debugger/BacktraceModel.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include namespace Debug { diff --git a/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.h b/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.h index d881cf0166..11759c649d 100644 --- a/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.h +++ b/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.h @@ -17,7 +17,7 @@ #include #include #include -#include +#include namespace HackStudio { diff --git a/Userland/DevTools/HackStudio/Debugger/DisassemblyModel.h b/Userland/DevTools/HackStudio/Debugger/DisassemblyModel.h index fdd8e3b03b..67cbeb4c94 100644 --- a/Userland/DevTools/HackStudio/Debugger/DisassemblyModel.h +++ b/Userland/DevTools/HackStudio/Debugger/DisassemblyModel.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include namespace Debug { diff --git a/Userland/DevTools/HackStudio/Debugger/DisassemblyWidget.h b/Userland/DevTools/HackStudio/Debugger/DisassemblyWidget.h index 9f32350e66..d695e600c6 100644 --- a/Userland/DevTools/HackStudio/Debugger/DisassemblyWidget.h +++ b/Userland/DevTools/HackStudio/Debugger/DisassemblyWidget.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include namespace HackStudio { diff --git a/Userland/DevTools/HackStudio/Debugger/RegistersModel.h b/Userland/DevTools/HackStudio/Debugger/RegistersModel.h index f8749f4c47..3004feada8 100644 --- a/Userland/DevTools/HackStudio/Debugger/RegistersModel.h +++ b/Userland/DevTools/HackStudio/Debugger/RegistersModel.h @@ -9,7 +9,7 @@ #include #include -#include +#include namespace HackStudio { diff --git a/Userland/DevTools/HackStudio/Debugger/VariablesModel.h b/Userland/DevTools/HackStudio/Debugger/VariablesModel.h index 5ab55a4d82..6350e99b8e 100644 --- a/Userland/DevTools/HackStudio/Debugger/VariablesModel.h +++ b/Userland/DevTools/HackStudio/Debugger/VariablesModel.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include namespace HackStudio { diff --git a/Userland/Libraries/LibC/sys/arch/x86_64/regs.h b/Userland/Libraries/LibC/sys/arch/x86_64/regs.h index b41fd67617..849a29624a 100644 --- a/Userland/Libraries/LibC/sys/arch/x86_64/regs.h +++ b/Userland/Libraries/LibC/sys/arch/x86_64/regs.h @@ -6,118 +6,41 @@ #pragma once -#include +#include -#define RREGISTER(num) \ - union { \ - u64 r##num; \ - struct { \ - u32 _unused##num; \ - union { \ - u32 r##num##d; \ - struct { \ - u16 __unused##num; \ - union { \ - u16 r##num##w; \ - struct { \ - u8 ___unused##num; \ - u8 r##num##b; \ - }; \ - }; \ - }; \ - }; \ - }; \ +#if defined(__cplusplus) && defined(__cpp_concepts) +# include +#else +# include +#endif + +#include + +#ifdef __cplusplus +struct [[gnu::packed]] PtraceRegisters : public __mcontext { +#if defined(__cplusplus) && defined(__cpp_concepts) + FlatPtr ip() const + { + return rip; } -#define GPREGISTER(letter) \ - union { \ - u64 r##letter##x; \ - struct \ - { \ - u32 _unused##letter; \ - union { \ - u32 e##letter##x; \ - struct \ - { \ - u16 __unused##letter; \ - union { \ - u16 letter##x; \ - struct { \ - u8 letter##h; \ - u8 letter##l; \ - }; \ - }; \ - }; \ - }; \ - }; \ + void set_ip(FlatPtr ip) + { + rip = ip; } -#define SPREGISTER(name) \ - union { \ - u64 r##name; \ - struct \ - { \ - u32 _unused##name; \ - union { \ - u32 e##name; \ - struct \ - { \ - u16 __unused##name; \ - union { \ - u16 name; \ - struct { \ - u8 ___unused##name; \ - u8 name##l; \ - }; \ - }; \ - }; \ - }; \ - }; \ + FlatPtr bp() const + { + return rbp; } -struct [[gnu::packed]] PtraceRegisters { - GPREGISTER(a); - GPREGISTER(b); - GPREGISTER(c); - GPREGISTER(d); - - SPREGISTER(sp); - SPREGISTER(bp); - SPREGISTER(si); - SPREGISTER(di); - SPREGISTER(ip); // technically there is no ipl, but what ever - - RREGISTER(8); - RREGISTER(9); - RREGISTER(10); - RREGISTER(11); - RREGISTER(12); - RREGISTER(13); - RREGISTER(14); - RREGISTER(15); - // flags - union { - u64 rflags; - struct { - u32 _; - union { - u32 eflags; - struct { - u16 __; - u16 flags; - }; - }; - }; - }; - - // These may not be used, unless we go back into compatibility mode - u32 cs; - u32 ss; - u32 ds; - u32 es; - u32 fs; - u32 gs; - - // FIXME: Add FPU registers and Flags - // FIXME: Add Ymm Xmm etc. + void set_bp(FlatPtr bp) + { + rbp = bp; + } +#endif }; + +#else +typedef struct __mcontext PthreadRegisters; +#endif diff --git a/Userland/Libraries/LibDebug/DebugInfo.h b/Userland/Libraries/LibDebug/DebugInfo.h index 3f7f204229..b73c272ca9 100644 --- a/Userland/Libraries/LibDebug/DebugInfo.h +++ b/Userland/Libraries/LibDebug/DebugInfo.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include namespace Debug { diff --git a/Userland/Libraries/LibDebug/DebugSession.h b/Userland/Libraries/LibDebug/DebugSession.h index 6084f73099..87fea886bc 100644 --- a/Userland/Libraries/LibDebug/DebugSession.h +++ b/Userland/Libraries/LibDebug/DebugSession.h @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Userland/Libraries/LibDebug/Dwarf/Expression.cpp b/Userland/Libraries/LibDebug/Dwarf/Expression.cpp index 6d6a5af72c..08dda504e5 100644 --- a/Userland/Libraries/LibDebug/Dwarf/Expression.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/Expression.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include namespace Debug::Dwarf::Expression { diff --git a/Userland/Libraries/LibDebug/ProcessInspector.h b/Userland/Libraries/LibDebug/ProcessInspector.h index ac3968fb7c..d72aac6b65 100644 --- a/Userland/Libraries/LibDebug/ProcessInspector.h +++ b/Userland/Libraries/LibDebug/ProcessInspector.h @@ -9,7 +9,7 @@ #include "LoadedLibrary.h" #include -#include +#include namespace Debug { diff --git a/Userland/Libraries/LibELF/Core.h b/Userland/Libraries/LibELF/Core.h index ca9a36db77..ae977b462a 100644 --- a/Userland/Libraries/LibELF/Core.h +++ b/Userland/Libraries/LibELF/Core.h @@ -7,7 +7,7 @@ #pragma once #include -#include +#include #ifndef KERNEL # include diff --git a/Userland/Utilities/functrace.cpp b/Userland/Utilities/functrace.cpp index c61787d656..3bcf652dce 100644 --- a/Userland/Utilities/functrace.cpp +++ b/Userland/Utilities/functrace.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Userland/Utilities/strace.cpp b/Userland/Utilities/strace.cpp index a7f5ae5f8a..fbe3f0722c 100644 --- a/Userland/Utilities/strace.cpp +++ b/Userland/Utilities/strace.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include