Added riscv and riscv64 support for Linux

Change-Id: I62cd157d00a87720db001072662a81d8eb9112b0
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/3873291
Reviewed-by: Mike Frysinger <vapier@chromium.org>
This commit is contained in:
Iacopo Colonnelli 2022-09-09 09:53:29 +02:00 committed by Mike Frysinger
parent e059dad5ea
commit 28cf16bc34
37 changed files with 4901 additions and 48 deletions

View file

@ -0,0 +1,168 @@
/* minidump_format.h: A cross-platform reimplementation of minidump-related
* portions of DbgHelp.h from the Windows Platform SDK.
*
* (This is C99 source, please don't corrupt it with C++.)
*
* This file contains the necessary definitions to read minidump files
* produced on RISCV and RISCV64. These files may be read on any platform
* provided that the alignments of these structures on the processing system
* are identical to the alignments of these structures on the producing
* system. For this reason, precise-sized types are used. The structures
* defined by this file have been laid out to minimize alignment problems by
* ensuring that all members are aligned on their natural boundaries.
* In some cases, tail-padding may be significant when different ABIs specify
* different tail-padding behaviors. To avoid problems when reading or
* writing affected structures, MD_*_SIZE macros are provided where needed,
* containing the useful size of the structures without padding.
*
* Structures that are defined by Microsoft to contain a zero-length array
* are instead defined here to contain an array with one element, as
* zero-length arrays are forbidden by standard C and C++. In these cases,
* *_minsize constants are provided to be used in place of sizeof. For a
* cleaner interface to these sizes when using C++, see minidump_size.h.
*
* These structures are also sufficient to populate minidump files.
*
* Because precise data type sizes are crucial for this implementation to
* function properly and portably, a set of primitive types with known sizes
* are used as the basis of each structure defined by this file.
*
* Author: Iacopo Colonnelli
*/
/*
* RISCV and RISCV64 support
*/
#ifndef GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_RISCV_H__
#define GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_RISCV_H__
#include "google_breakpad/common/breakpad_types.h"
#define MD_FLOATINGSAVEAREA_RISCV_FPR_COUNT 32
#if defined(__riscv)
# if __riscv_flen == 32
typedef uint32_t riscv_fpr_size;
# elif __riscv_flen == 64
typedef uint64_t riscv_fpr_size;
# elif __riscv_flen == 128
typedef uint128_struct riscv_fpr_size;
# else
# error "Unexpected __riscv_flen"
# endif
#else
typedef uint32_t riscv_fpr_size;
#endif
#define MD_CONTEXT_RISCV_GPR_COUNT 32
typedef struct {
/* 32 floating point registers, f0 .. f31. */
riscv_fpr_size regs[MD_FLOATINGSAVEAREA_RISCV_FPR_COUNT];
uint32_t fpcsr;
} MDFloatingSaveAreaRISCV;
enum MDRISCVRegisterNumbers {
MD_CONTEXT_RISCV_REG_PC = 0,
MD_CONTEXT_RISCV_REG_RA = 1,
MD_CONTEXT_RISCV_REG_SP = 2,
};
/* For (MDRawContextRISCV).context_flags. These values indicate the type of
* context stored in the structure. */
#define MD_CONTEXT_RISCV 0x00800000
#define MD_CONTEXT_RISCV_INTEGER (MD_CONTEXT_RISCV | 0x00000001)
#define MD_CONTEXT_RISCV_FLOATING_POINT (MD_CONTEXT_RISCV | 0x00000004)
#define MD_CONTEXT_RISCV_FULL (MD_CONTEXT_RISCV_INTEGER | \
MD_CONTEXT_RISCV_FLOATING_POINT)
typedef struct {
/* Determines which fields of this struct are populated */
uint32_t context_flags;
uint32_t pc;
uint32_t ra;
uint32_t sp;
uint32_t gp;
uint32_t tp;
uint32_t t0;
uint32_t t1;
uint32_t t2;
uint32_t s0;
uint32_t s1;
uint32_t a0;
uint32_t a1;
uint32_t a2;
uint32_t a3;
uint32_t a4;
uint32_t a5;
uint32_t a6;
uint32_t a7;
uint32_t s2;
uint32_t s3;
uint32_t s4;
uint32_t s5;
uint32_t s6;
uint32_t s7;
uint32_t s8;
uint32_t s9;
uint32_t s10;
uint32_t s11;
uint32_t t3;
uint32_t t4;
uint32_t t5;
uint32_t t6;
MDFloatingSaveAreaRISCV float_save;
} MDRawContextRISCV;
/* For (MDRawContextRISCV64).context_flags. These values indicate the type of
* context stored in the structure. */
#define MD_CONTEXT_RISCV64 0x08000000
#define MD_CONTEXT_RISCV64_INTEGER (MD_CONTEXT_RISCV64 | 0x00000001)
#define MD_CONTEXT_RISCV64_FLOATING_POINT (MD_CONTEXT_RISCV64 | 0x00000004)
#define MD_CONTEXT_RISCV64_FULL (MD_CONTEXT_RISCV64_INTEGER | \
MD_CONTEXT_RISCV64_FLOATING_POINT)
typedef struct {
/* Determines which fields of this struct are populated */
uint32_t context_flags;
uint64_t pc;
uint64_t ra;
uint64_t sp;
uint64_t gp;
uint64_t tp;
uint64_t t0;
uint64_t t1;
uint64_t t2;
uint64_t s0;
uint64_t s1;
uint64_t a0;
uint64_t a1;
uint64_t a2;
uint64_t a3;
uint64_t a4;
uint64_t a5;
uint64_t a6;
uint64_t a7;
uint64_t s2;
uint64_t s3;
uint64_t s4;
uint64_t s5;
uint64_t s6;
uint64_t s7;
uint64_t s8;
uint64_t s9;
uint64_t s10;
uint64_t s11;
uint64_t t3;
uint64_t t4;
uint64_t t5;
uint64_t t6;
MDFloatingSaveAreaRISCV float_save;
} MDRawContextRISCV64;
#endif /* GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_RISCV_H__ */

View file

@ -117,6 +117,7 @@ typedef struct {
#include "minidump_cpu_mips.h"
#include "minidump_cpu_ppc.h"
#include "minidump_cpu_ppc64.h"
#include "minidump_cpu_riscv.h"
#include "minidump_cpu_sparc.h"
#include "minidump_cpu_x86.h"
@ -683,6 +684,8 @@ typedef enum {
MD_CPU_ARCHITECTURE_PPC64 = 0x8002, /* Breakpad-defined value for PPC64 */
MD_CPU_ARCHITECTURE_ARM64_OLD = 0x8003, /* Breakpad-defined value for ARM64 */
MD_CPU_ARCHITECTURE_MIPS64 = 0x8004, /* Breakpad-defined value for MIPS64 */
MD_CPU_ARCHITECTURE_RISCV = 0x8005, /* Breakpad-defined value for RISCV */
MD_CPU_ARCHITECTURE_RISCV64 = 0x8006, /* Breakpad-defined value for RISCV64 */
MD_CPU_ARCHITECTURE_UNKNOWN = 0xffff /* PROCESSOR_ARCHITECTURE_UNKNOWN */
} MDCPUArchitecture;

View file

@ -53,14 +53,16 @@ class DumpContext : public DumpObject {
// Returns raw CPU-specific context data for the named CPU type. If the
// context data does not match the CPU type or does not exist, returns NULL.
const MDRawContextAMD64* GetContextAMD64() const;
const MDRawContextARM* GetContextARM() const;
const MDRawContextARM64* GetContextARM64() const;
const MDRawContextMIPS* GetContextMIPS() const;
const MDRawContextPPC* GetContextPPC() const;
const MDRawContextPPC64* GetContextPPC64() const;
const MDRawContextSPARC* GetContextSPARC() const;
const MDRawContextX86* GetContextX86() const;
const MDRawContextAMD64* GetContextAMD64() const;
const MDRawContextARM* GetContextARM() const;
const MDRawContextARM64* GetContextARM64() const;
const MDRawContextMIPS* GetContextMIPS() const;
const MDRawContextPPC* GetContextPPC() const;
const MDRawContextPPC64* GetContextPPC64() const;
const MDRawContextSPARC* GetContextSPARC() const;
const MDRawContextX86* GetContextX86() const;
const MDRawContextRISCV* GetContextRISCV() const;
const MDRawContextRISCV64* GetContextRISCV64() const;
// A convenience method to get the instruction pointer out of the
// MDRawContext, since it varies per-CPU architecture.
@ -86,6 +88,8 @@ class DumpContext : public DumpObject {
void SetContextARM(MDRawContextARM* arm);
void SetContextARM64(MDRawContextARM64* arm64);
void SetContextMIPS(MDRawContextMIPS* ctx_mips);
void SetContextRISCV(MDRawContextRISCV* riscv);
void SetContextRISCV64(MDRawContextRISCV64* riscv64);
// Free the CPU-specific context structure.
void FreeContext();
@ -93,17 +97,19 @@ class DumpContext : public DumpObject {
private:
// The CPU-specific context structure.
union {
MDRawContextBase* base;
MDRawContextX86* x86;
MDRawContextPPC* ppc;
MDRawContextPPC64* ppc64;
MDRawContextAMD64* amd64;
MDRawContextBase* base;
MDRawContextX86* x86;
MDRawContextPPC* ppc;
MDRawContextPPC64* ppc64;
MDRawContextAMD64* amd64;
// on Solaris SPARC, sparc is defined as a numeric constant,
// so variables can NOT be named as sparc
MDRawContextSPARC* ctx_sparc;
MDRawContextARM* arm;
MDRawContextARM64* arm64;
MDRawContextMIPS* ctx_mips;
MDRawContextSPARC* ctx_sparc;
MDRawContextARM* arm;
MDRawContextARM64* arm64;
MDRawContextMIPS* ctx_mips;
MDRawContextRISCV* riscv;
MDRawContextRISCV64* riscv64;
} context_;
// Store this separately because of the weirdo AMD64 context

View file

@ -402,6 +402,118 @@ struct StackFrameMIPS : public StackFrame {
int context_validity;
};
struct StackFrameRISCV : public StackFrame {
enum ContextValidity {
CONTEXT_VALID_NONE = 0,
CONTEXT_VALID_PC = 1 << 0,
CONTEXT_VALID_RA = 1 << 1,
CONTEXT_VALID_SP = 1 << 2,
CONTEXT_VALID_GP = 1 << 3,
CONTEXT_VALID_TP = 1 << 4,
CONTEXT_VALID_T0 = 1 << 5,
CONTEXT_VALID_T1 = 1 << 6,
CONTEXT_VALID_T2 = 1 << 7,
CONTEXT_VALID_S0 = 1 << 8,
CONTEXT_VALID_S1 = 1 << 9,
CONTEXT_VALID_A0 = 1 << 10,
CONTEXT_VALID_A1 = 1 << 11,
CONTEXT_VALID_A2 = 1 << 12,
CONTEXT_VALID_A3 = 1 << 13,
CONTEXT_VALID_A4 = 1 << 14,
CONTEXT_VALID_A5 = 1 << 15,
CONTEXT_VALID_A6 = 1 << 16,
CONTEXT_VALID_A7 = 1 << 17,
CONTEXT_VALID_S2 = 1 << 18,
CONTEXT_VALID_S3 = 1 << 19,
CONTEXT_VALID_S4 = 1 << 20,
CONTEXT_VALID_S5 = 1 << 21,
CONTEXT_VALID_S6 = 1 << 22,
CONTEXT_VALID_S7 = 1 << 23,
CONTEXT_VALID_S8 = 1 << 24,
CONTEXT_VALID_S9 = 1 << 25,
CONTEXT_VALID_S10 = 1 << 26,
CONTEXT_VALID_S11 = 1 << 27,
CONTEXT_VALID_T3 = 1 << 28,
CONTEXT_VALID_T4 = 1 << 29,
CONTEXT_VALID_T5 = 1 << 30,
CONTEXT_VALID_T6 = 1 << 31,
CONTEXT_VALID_ALL = ~CONTEXT_VALID_NONE
};
StackFrameRISCV() : context(), context_validity(CONTEXT_VALID_NONE) {}
// Register state. This is only fully valid for the topmost frame in a
// stack. In other frames, which registers are present depends on what
// debugging information were available. Refer to 'context_validity' below.
MDRawContextRISCV context;
// For each register in context whose value has been recovered,
// the corresponding CONTEXT_VALID_ bit in 'context_validity' is set.
//
// context_validity's type should actually be ContextValidity, but
// type int is used instead because the bitwise inclusive or operator
// yields an int when applied to enum values, and C++ doesn't
// silently convert from ints to enums.
int context_validity;
};
struct StackFrameRISCV64 : public StackFrame {
enum ContextValidity {
CONTEXT_VALID_NONE = 0,
CONTEXT_VALID_PC = 1 << 0,
CONTEXT_VALID_RA = 1 << 1,
CONTEXT_VALID_SP = 1 << 2,
CONTEXT_VALID_GP = 1 << 3,
CONTEXT_VALID_TP = 1 << 4,
CONTEXT_VALID_T0 = 1 << 5,
CONTEXT_VALID_T1 = 1 << 6,
CONTEXT_VALID_T2 = 1 << 7,
CONTEXT_VALID_S0 = 1 << 8,
CONTEXT_VALID_S1 = 1 << 9,
CONTEXT_VALID_A0 = 1 << 10,
CONTEXT_VALID_A1 = 1 << 11,
CONTEXT_VALID_A2 = 1 << 12,
CONTEXT_VALID_A3 = 1 << 13,
CONTEXT_VALID_A4 = 1 << 14,
CONTEXT_VALID_A5 = 1 << 15,
CONTEXT_VALID_A6 = 1 << 16,
CONTEXT_VALID_A7 = 1 << 17,
CONTEXT_VALID_S2 = 1 << 18,
CONTEXT_VALID_S3 = 1 << 19,
CONTEXT_VALID_S4 = 1 << 20,
CONTEXT_VALID_S5 = 1 << 21,
CONTEXT_VALID_S6 = 1 << 22,
CONTEXT_VALID_S7 = 1 << 23,
CONTEXT_VALID_S8 = 1 << 24,
CONTEXT_VALID_S9 = 1 << 25,
CONTEXT_VALID_S10 = 1 << 26,
CONTEXT_VALID_S11 = 1 << 27,
CONTEXT_VALID_T3 = 1 << 28,
CONTEXT_VALID_T4 = 1 << 29,
CONTEXT_VALID_T5 = 1 << 30,
CONTEXT_VALID_T6 = 1 << 31,
CONTEXT_VALID_ALL = ~CONTEXT_VALID_NONE
};
StackFrameRISCV64() : context(), context_validity(CONTEXT_VALID_NONE) {}
// Register state. This is only fully valid for the topmost frame in a
// stack. In other frames, which registers are present depends on what
// debugging information were available. Refer to 'context_validity' below.
MDRawContextRISCV64 context;
// For each register in context whose value has been recovered,
// the corresponding CONTEXT_VALID_ bit in 'context_validity' is set.
//
// context_validity's type should actually be ContextValidity, but
// type int is used instead because the bitwise inclusive or operator
// yields an int when applied to enum values, and C++ doesn't
// silently convert from ints to enums.
int context_validity;
};
} // namespace google_breakpad
#endif // GOOGLE_BREAKPAD_PROCESSOR_STACK_FRAME_CPU_H__