Compare commits

..

No commits in common. "48046202b326c5c75527ceb4daa8527995c3f238" and "254500df2c2d873e20b22b83412de38447657761" have entirely different histories.

4 changed files with 3 additions and 304 deletions

View File

@ -1,74 +0,0 @@
From 26cf0d75eda1c2530640b8bf9699785a47c78a24 Mon Sep 17 00:00:00 2001
From: doupengda <doupengda@loongson.cn>
Date: Tue, 14 May 2024 11:07:07 +0800
Subject: [PATCH] add loongarch64 support
---
configure | 6 +++++-
machines.h | 31 +++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/configure b/configure
index 7c7280f..60fd170 100755
--- a/configure
+++ b/configure
@@ -59,9 +59,13 @@ case `uname -m` in
machine="aarch64"
CFLAGS="$CFLAGS -DMLX_AARCH64"
;;
+'loongarch64')
+ machine="loongarch64"
+ CFLAGS="$CFLAGS -DMLX_LOONGARCH64"
+ ;;
*)
echo "Error: unsupported machine: `uname -m`."
- echo "Only x86, x86_64, arm, and aarch64 are supported."
+ echo "Only x86, x86_64, arm, loongarch and aarch64 are supported."
exit 2
;;
esac
diff --git a/machines.h b/machines.h
index cbbe69d..3e184d5 100644
--- a/machines.h
+++ b/machines.h
@@ -87,6 +87,37 @@ static inline int is_breakpoint(pid_t pid, uintptr_t address)
return (ptrace_get_data(pid, address) & 0xFF) == 0xCC;
}
+#elif defined(MLX_LOONGARCH64)
+static inline uintptr_t call_return_address(pid_t pid, registers_info_t *regs)
+{
+ return ptrace_get_data(pid, regs->regs[3]);
+}
+static inline uintptr_t call_return_value(registers_info_t *regs)
+{
+ return regs->regs[1];
+}
+static inline uintptr_t call_arg1(pid_t pid, registers_info_t *regs)
+{
+ return regs->regs[6];
+}
+static inline uintptr_t call_arg2(pid_t pid, registers_info_t *regs)
+{
+ return regs->regs[7];
+}
+static inline uintptr_t pc_unwind(pid_t pid, registers_info_t *regs)
+{
+ return regs->csr_era;
+}
+static inline void set_breakpoint(pid_t pid, uintptr_t address, uintptr_t code)
+{
+ ptrace_set_data(pid, address, (code & 0x002a0000));
+}
+static inline int is_breakpoint(pid_t pid, uintptr_t address)
+{
+ return ptrace_get_data(pid, address) == 0x002a0000;
+}
+
+
#elif defined(MLX_ARMv7)
static inline uintptr_t call_return_address(pid_t pid, registers_info_t *regs)
{
--
2.43.0

View File

@ -1,78 +0,0 @@
diff -ur memleax-1.1.1/configure memleax-1.1.1/configure
--- memleax-1.1.1/configure 2023-06-30 16:52:49.401032162 +0800
+++ memleax-1.1.1/configure 2023-06-30 16:56:52.793616961 +0800
@@ -63,9 +63,13 @@
machine="loongarch64"
CFLAGS="$CFLAGS -DMLX_LOONGARCH64"
;;
+'riscv64')
+ machine="riscv"
+ CFLAGS="$CFLAGS -DMLX_RISCV64"
+ ;;
*)
echo "Error: unsupported machine: `uname -m`."
- echo "Only x86, x86_64, arm, loongarch and aarch64 are supported."
+ echo "Only x86, x86_64, arm, loongarch, riscv and aarch64 are supported."
exit 2
;;
esac
@@ -159,7 +163,7 @@
cat << EOF > Makefile
CFLAGS = $CFLAGS -g -O2 -Wall
-LDLIBS = $LDLIBS
+LDLIBS = $LDLIBS -llzma
LDFLAGS = $LDFLAGS
PREFIX = $prefix
DESTDIR =
diff -ur memleax-1.1.1/machines.h memleax-1.1.1/machines.h
--- memleax-1.1.1/machines.h 2023-06-30 16:52:49.401032162 +0800
+++ memleax-1.1.1/machines.h 2023-06-30 16:30:58.889630806 +0800
@@ -177,6 +177,35 @@
{
return ptrace_get_data(pid, address) == 0xd4200000;
}
+#elif defined(MLX_RISCV64)
+static inline uintptr_t call_return_address(pid_t pid, registers_info_t *regs)
+{
+ return regs->ra;
+}
+static inline uintptr_t call_return_value(registers_info_t *regs)
+{
+ return regs->a0;
+}
+static inline uintptr_t call_arg1(pid_t pid, registers_info_t *regs)
+{
+ return regs->a0;
+}
+static inline uintptr_t call_arg2(pid_t pid, registers_info_t *regs)
+{
+ return regs->a1;
+}
+static inline uintptr_t pc_unwind(pid_t pid, registers_info_t *regs)
+{
+ return regs->pc;
+}
+static inline void set_breakpoint(pid_t pid, uintptr_t address, uintptr_t code)
+{
+ ptrace_set_data(pid, address, 0x00100073);
+}
+static inline int is_breakpoint(pid_t pid, uintptr_t address)
+{
+ return ptrace_get_data(pid, address) == 0x00100073;
+}
#endif
#endif
diff -ur memleax-1.1.1/ptrace_utils.h memleax-1.1.1/ptrace_utils.h
--- memleax-1.1.1/ptrace_utils.h 2018-01-04 06:05:08.000000000 +0800
+++ memleax-1.1.1/ptrace_utils.h 2023-06-30 16:31:47.693773352 +0800
@@ -16,7 +16,7 @@
#include <elf.h>
#include <sys/uio.h>
-
+#include <asm/ptrace.h>
#ifdef MLX_ARMv7
typedef struct user_regs registers_info_t;
#else

View File

@ -1,130 +0,0 @@
diff --git a/configure b/configure
index 583efbc..1bd90c5 100755
--- a/configure
+++ b/configure
@@ -67,9 +67,14 @@ case `uname -m` in
machine="riscv"
CFLAGS="$CFLAGS -DMLX_RISCV64"
;;
+'sw_64')
+ machine="sw_64"
+ CFLAGS="$CFLAGS -DMLX_SW_64"
+ LDFLAGS="$LDFLAGS -llzma"
+ ;;
*)
echo "Error: unsupported machine: `uname -m`."
- echo "Only x86, x86_64, arm, loongarch, riscv and aarch64 are supported."
+ echo "Only x86, x86_64, arm, loongarch, riscv, sw_64 and aarch64 are supported."
exit 2
;;
esac
diff --git a/machines.h b/machines.h
index c92da46..97eb696 100644
--- a/machines.h
+++ b/machines.h
@@ -206,6 +206,35 @@ static inline int is_breakpoint(pid_t pid, uintptr_t address)
{
return ptrace_get_data(pid, address) == 0x00100073;
}
+#elif defined(MLX_SW_64)
+static inline uintptr_t call_return_address(pid_t pid, registers_info_t *regs)
+{
+ return regs->regs[30];
+}
+static inline uintptr_t call_return_value(registers_info_t *regs)
+{
+ return regs->regs[0];
+}
+static inline uintptr_t call_arg1(pid_t pid, registers_info_t *regs)
+{
+ return regs->regs[0];
+}
+static inline uintptr_t call_arg2(pid_t pid, registers_info_t *regs)
+{
+ return regs->regs[1];
+}
+static inline uintptr_t pc_unwind(pid_t pid, registers_info_t *regs)
+{
+ return regs->pc;
+}
+static inline void set_breakpoint(pid_t pid, uintptr_t address, uintptr_t code)
+{
+ ptrace_set_data(pid, address, 0x00000080);
+}
+static inline int is_breakpoint(pid_t pid, uintptr_t address)
+{
+ return ptrace_get_data(pid, address) == 0x00000080;
+}
#endif
#endif
diff --git a/ptrace_utils.h b/ptrace_utils.h
index a9ef0f4..9a10327 100644
--- a/ptrace_utils.h
+++ b/ptrace_utils.h
@@ -17,8 +17,65 @@
#include <elf.h>
#include <sys/uio.h>
#include <asm/ptrace.h>
+
+#ifdef MLX_SW_64
+#ifndef __ASSEMBLY__
+
+struct pt_regs {
+ union {
+ struct user_pt_regs user_regs;
+ struct {
+ unsigned long r0;
+ unsigned long r1;
+ unsigned long r2;
+ unsigned long r3;
+ unsigned long r4;
+ unsigned long r5;
+ unsigned long r6;
+ unsigned long r7;
+ unsigned long r8;
+ unsigned long r9;
+ unsigned long r10;
+ unsigned long r11;
+ unsigned long r12;
+ unsigned long r13;
+ unsigned long r14;
+ unsigned long r15;
+ unsigned long r16;
+ unsigned long r17;
+ unsigned long r18;
+ unsigned long r19;
+ unsigned long r20;
+ unsigned long r21;
+ unsigned long r22;
+ unsigned long r23;
+ unsigned long r24;
+ unsigned long r25;
+ unsigned long r26;
+ unsigned long r27;
+ unsigned long r28;
+ unsigned long gp;
+ unsigned long sp;
+ unsigned long pc;
+ unsigned long ps;
+ };
+ };
+ /* These are saved by HMcode: */
+ unsigned long hm_ps;
+ unsigned long hm_pc;
+ unsigned long hm_gp;
+ unsigned long hm_r16;
+ unsigned long hm_r17;
+ unsigned long hm_r18;
+};
+
+#endif
+#endif
+
#ifdef MLX_ARMv7
typedef struct user_regs registers_info_t;
+ #elif (defined MLX_SW_64)
+typedef struct user_pt_regs registers_info_t;
#else
typedef struct user_regs_struct registers_info_t;
#endif

View File

@ -1,15 +1,12 @@
Name: memleax
Version: 1.1.1
Release: 9
Release: 4
Summary: Memory lead detection tool
License: GPLv2
URL: https://github.com/WuBingzheng/memleax
Source0: https://github.com/WuBingzheng/memleax/archive/v%{version}.tar.gz#/memleax-%{version}.tar.gz
Patch0: 0001-add-loongarch64-support.patch
Patch1: 0002-add-riscv64-support.patch
Patch2: 0003-add-sw_64-support-not-upstream-modified.patch
BuildRequires: make libunwind-devel elfutils-devel gcc
BuildRequires: make libunwind-devel elfutils-devel gdb gcc
%description
memleax debugs memory leak of a running process by attaching it.
@ -27,8 +24,7 @@ memleax follows new threads, but not forked processes.
If you want to debug multiple processes, just run multiple memleax.
%prep
%setup -q
%autosetup -n %{name}-%{version} -p1
%setup -q -n %{name}-%{version}/
%build
./configure
@ -50,21 +46,6 @@ make install DESTDIR="%{buildroot}"
%{_mandir}/man1/%{name}.1*
%changelog
* Mon Feb 17 2025 maqi <maqi@uniontech.com> - 1.1.1-9
- add support sw_64
* Tue May 14 2024 wangshuo <wangshuo@kylinos.cn> - 1.1.1-8
- Resolve compilation errors for loongarch64
* Fri Jun 30 2023 zhangxiang <zhangxiang@iscas.ac.cn> - 1.1.1-7
- add riscv64 support
* Wed Dec 14 2022 doupengda <doupengda@loongson.cn> - 1.1.1-6
- add loongarch64 support
* Wed Aug 04 2021 chenyanpanHW <chenyanpan@huawei.com> - 1.1.1-5
- DESC: delete BuildRequires gdb
* Mon Jun 28 2021 wulei <wulei80@huawei.com> - 1.1.1-4
- fix missing gcc