[ltrace-commits] 01/01: aarch64 scaffolding

Petr Machata pmachata-guest at moszumanska.debian.org
Thu Jan 23 23:52:55 UTC 2014


This is an automated email from the git hooks/post-receive script.

pmachata-guest pushed a commit to branch pmachata/aarch64
in repository ltrace.

commit 3d2c4ce953b894f59c73a35205c46b17caa421ce
Author: Petr Machata <pmachata at redhat.com>
Date:   Fri Jan 24 00:50:06 2014 +0100

    aarch64 scaffolding
---
 configure.ac                                |   3 +-
 sysdeps/linux-gnu/Makefile.am               |   4 +-
 sysdeps/linux-gnu/{ => aarch64}/Makefile.am |  27 ++-----
 sysdeps/linux-gnu/aarch64/arch.h            |  37 ++++++++++
 sysdeps/linux-gnu/aarch64/fetch.c           |  82 ++++++++++++++++++++++
 sysdeps/linux-gnu/aarch64/plt.c             |  39 +++++++++++
 sysdeps/linux-gnu/aarch64/ptrace.h          |  22 ++++++
 sysdeps/linux-gnu/aarch64/regs.c            | 105 ++++++++++++++++++++++++++++
 sysdeps/linux-gnu/aarch64/signalent.h       |  52 ++++++++++++++
 sysdeps/linux-gnu/aarch64/syscallent.h      |  21 ++++++
 sysdeps/linux-gnu/aarch64/trace.c           |  83 ++++++++++++++++++++++
 11 files changed, 451 insertions(+), 24 deletions(-)

diff --git a/configure.ac b/configure.ac
index c6e6bf0..0e9a124 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,6 +1,6 @@
 # -*- Autoconf -*-
 # This file is part of ltrace.
-# Copyright (C) 2010,2012,2013 Petr Machata, Red Hat Inc.
+# Copyright (C) 2010,2012,2013,2014 Petr Machata, Red Hat Inc.
 # Copyright (C) 2010,2011 Joe Damato
 # Copyright (C) 2010 Marc Kleine-Budde
 # Copyright (C) 2010 Zachary T Welch
@@ -399,6 +399,7 @@ AC_CONFIG_FILES([
 	Makefile
 	sysdeps/Makefile
 	sysdeps/linux-gnu/Makefile
+	sysdeps/linux-gnu/aarch64/Makefile
 	sysdeps/linux-gnu/alpha/Makefile
 	sysdeps/linux-gnu/arm/Makefile
 	sysdeps/linux-gnu/cris/Makefile
diff --git a/sysdeps/linux-gnu/Makefile.am b/sysdeps/linux-gnu/Makefile.am
index ecee577..ec26162 100644
--- a/sysdeps/linux-gnu/Makefile.am
+++ b/sysdeps/linux-gnu/Makefile.am
@@ -1,4 +1,5 @@
 # This file is part of ltrace.
+# Copyright (C) 2014 Petr Machata, Red Hat, Inc.
 # Copyright (C) 2010,2012 Marc Kleine-Budde, Pengutronix
 #
 # This program is free software; you can redistribute it and/or
@@ -16,7 +17,8 @@
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 # 02110-1301 USA
 
-DIST_SUBDIRS = alpha arm cris ia64 m68k metag mips ppc s390 sparc x86
+DIST_SUBDIRS = aarch64 alpha arm cris ia64 m68k metag mips ppc s390	\
+	       sparc x86
 
 SUBDIRS = \
 	$(HOST_CPU)
diff --git a/sysdeps/linux-gnu/Makefile.am b/sysdeps/linux-gnu/aarch64/Makefile.am
similarity index 58%
copy from sysdeps/linux-gnu/Makefile.am
copy to sysdeps/linux-gnu/aarch64/Makefile.am
index ecee577..0af4e6e 100644
--- a/sysdeps/linux-gnu/Makefile.am
+++ b/sysdeps/linux-gnu/aarch64/Makefile.am
@@ -1,5 +1,5 @@
 # This file is part of ltrace.
-# Copyright (C) 2010,2012 Marc Kleine-Budde, Pengutronix
+# Copyright (C) 2014 Petr Machata, Red Hat, Inc.
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -16,27 +16,10 @@
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 # 02110-1301 USA
 
-DIST_SUBDIRS = alpha arm cris ia64 m68k metag mips ppc s390 sparc x86
+noinst_LTLIBRARIES = ../libcpu.la
 
-SUBDIRS = \
-	$(HOST_CPU)
+___libcpu_la_SOURCES = fetch.c plt.c regs.c trace.c
 
-noinst_LTLIBRARIES = \
-	../libos.la
+noinst_HEADERS = arch.h ptrace.h signalent.h syscallent.h
 
-___libos_la_SOURCES = events.c trace.c proc.c breakpoint.c hooks.c
-
-___libos_la_LIBADD = \
-	libcpu.la
-
-noinst_HEADERS = arch_syscallent.h signalent1.h syscallent1.h trace.h	\
-	trace-defs.h events.h os.h
-
-EXTRA_DIST = \
-	arch_mksyscallent \
-	mksignalent \
-	mksyscallent \
-	mksyscallent_s390
-
-MAINTAINERCLEANFILES = \
-	Makefile.in
+MAINTAINERCLEANFILES = Makefile.in
diff --git a/sysdeps/linux-gnu/aarch64/arch.h b/sysdeps/linux-gnu/aarch64/arch.h
new file mode 100644
index 0000000..4137613
--- /dev/null
+++ b/sysdeps/linux-gnu/aarch64/arch.h
@@ -0,0 +1,37 @@
+/*
+ * This file is part of ltrace.
+ * Copyright (C) 2014 Petr Machata, Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+#ifndef LTRACE_AARCH64_ARCH_H
+#define LTRACE_AARCH64_ARCH_H
+
+/* | 31                 21 | 20       5 | 4       0 | *
+ * | 1 1 0 1 0 1 0 0 0 0 1 |    imm16   | 0 0 0 0 0 | */
+#define BREAKPOINT_VALUE { 0xd4, 0x20, 0, 0 }
+#define BREAKPOINT_LENGTH 4
+#define DECR_PC_AFTER_BREAK 0
+
+#define LT_ELFCLASS	ELFCLASS64
+#define LT_ELF_MACHINE	EM_AARCH64
+
+#define ARCH_HAVE_FETCH_ARG
+#define ARCH_ENDIAN_BIG
+#define ARCH_HAVE_SIZEOF
+#define ARCH_HAVE_ALIGNOF
+
+#endif /* LTRACE_AARCH64_ARCH_H */
diff --git a/sysdeps/linux-gnu/aarch64/fetch.c b/sysdeps/linux-gnu/aarch64/fetch.c
new file mode 100644
index 0000000..bf3d403
--- /dev/null
+++ b/sysdeps/linux-gnu/aarch64/fetch.c
@@ -0,0 +1,82 @@
+/*
+ * This file is part of ltrace.
+ * Copyright (C) 2014 Petr Machata, Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "fetch.h"
+#include "proc.h"
+#include "type.h"
+#include "value.h"
+
+struct fetch_context
+{
+};
+
+struct fetch_context *
+arch_fetch_arg_init(enum tof type, struct process *proc,
+		    struct arg_type_info *ret_info)
+{
+	return NULL;
+}
+
+struct fetch_context *
+arch_fetch_arg_clone(struct process *proc, struct fetch_context *context)
+{
+	struct fetch_context *ret = malloc(sizeof(*ret));
+	if (ret == NULL)
+		return NULL;
+	return memcpy(ret, context, sizeof(*ret));
+}
+
+int
+arch_fetch_arg_next(struct fetch_context *context, enum tof type,
+		    struct process *proc, struct arg_type_info *info,
+		    struct value *valuep)
+{
+	return -1;
+}
+
+int
+arch_fetch_retval(struct fetch_context *context, enum tof type,
+		  struct process *proc, struct arg_type_info *info,
+		  struct value *valuep)
+{
+	return -1;
+}
+
+void
+arch_fetch_arg_done(struct fetch_context *context)
+{
+	if (context != NULL)
+		free(context);
+}
+
+size_t
+arch_type_sizeof(struct process *proc, struct arg_type_info *arg)
+{
+	return (size_t) -2;
+}
+
+size_t
+arch_type_alignof(struct process *proc, struct arg_type_info *arg)
+{
+	return (size_t) -2;
+}
diff --git a/sysdeps/linux-gnu/aarch64/plt.c b/sysdeps/linux-gnu/aarch64/plt.c
new file mode 100644
index 0000000..a657aab
--- /dev/null
+++ b/sysdeps/linux-gnu/aarch64/plt.c
@@ -0,0 +1,39 @@
+/*
+ * This file is part of ltrace.
+ * Copyright (C) 2014 Petr Machata, Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include <gelf.h>
+
+#include "backend.h"
+#include "proc.h"
+#include "library.h"
+#include "ltrace-elf.h"
+
+arch_addr_t
+sym2addr(struct process *proc, struct library_symbol *sym)
+{
+	return sym->enter_addr;
+}
+
+GElf_Addr
+arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela *rela)
+{
+	assert(!"arch_plt_sym_val not implemented");
+	abort();
+}
diff --git a/sysdeps/linux-gnu/aarch64/ptrace.h b/sysdeps/linux-gnu/aarch64/ptrace.h
new file mode 100644
index 0000000..283c314
--- /dev/null
+++ b/sysdeps/linux-gnu/aarch64/ptrace.h
@@ -0,0 +1,22 @@
+/*
+ * This file is part of ltrace.
+ * Copyright (C) 2014 Petr Machata, Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include <sys/ptrace.h>
+#include <asm/ptrace.h>
diff --git a/sysdeps/linux-gnu/aarch64/regs.c b/sysdeps/linux-gnu/aarch64/regs.c
new file mode 100644
index 0000000..6b58ef1
--- /dev/null
+++ b/sysdeps/linux-gnu/aarch64/regs.c
@@ -0,0 +1,105 @@
+/*
+ * This file is part of ltrace.
+ * Copyright (C) 2014 Petr Machata, Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include <sys/ptrace.h>
+#include <asm/ptrace.h>
+#include <linux/uio.h>
+#include <assert.h>
+#include <stdlib.h>
+
+#include "backend.h"
+#include "proc.h"
+
+#define PC_OFF (32 * 4)
+
+int
+aarch64_read_gregs(struct process *proc, struct user_pt_regs *regs)
+{
+	*regs = (struct user_pt_regs) {};
+	struct iovec iovec;
+	iovec.iov_base = regs;
+	iovec.iov_len = sizeof *regs;
+	return ptrace(PTRACE_GETREGSET, proc->pid, NT_PRSTATUS, &iovec) < 0
+		? -1 : 0;
+}
+
+int
+aarch64_write_gregs(struct process *proc, struct user_pt_regs *regs)
+{
+	struct iovec iovec;
+	iovec.iov_base = regs;
+	iovec.iov_len = sizeof *regs;
+	return ptrace(PTRACE_SETREGSET, proc->pid, NT_PRSTATUS, &iovec) < 0
+		? -1 : 0;
+}
+
+arch_addr_t
+get_instruction_pointer(struct process *proc)
+{
+	struct user_pt_regs regs;
+	if (aarch64_read_gregs(proc, &regs) < 0) {
+		fprintf(stderr, "get_instruction_pointer: "
+			"Couldn't read registers of %d.\n", proc->pid);
+		return 0;
+	}
+
+	/* 
+	char buf[128];
+	sprintf(buf, "cat /proc/%d/maps", proc->pid);
+	system(buf);
+	*/
+
+	/* XXX double cast */
+	return (arch_addr_t) (uintptr_t) regs.pc;
+}
+
+void
+set_instruction_pointer(struct process *proc, arch_addr_t addr)
+{
+	struct user_pt_regs regs;
+	if (aarch64_read_gregs(proc, &regs) < 0) {
+		fprintf(stderr, "get_instruction_pointer: "
+			"Couldn't read registers of %d.\n", proc->pid);
+		return;
+	}
+
+	/* XXX double cast */
+	regs.pc = (uint64_t) (uintptr_t) addr;
+
+	if (aarch64_write_gregs(proc, &regs) < 0) {
+		fprintf(stderr, "get_instruction_pointer: "
+			"Couldn't write registers of %d.\n", proc->pid);
+		return;
+	}
+}
+
+arch_addr_t
+get_stack_pointer(struct process *proc)
+{
+	assert(!"get_stack_pointer not implemented");
+	abort();
+}
+
+arch_addr_t
+get_return_addr(struct process *proc, arch_addr_t stack_pointer)
+{
+	assert(!"get_return_addr not implemented");
+	abort();
+}
diff --git a/sysdeps/linux-gnu/aarch64/signalent.h b/sysdeps/linux-gnu/aarch64/signalent.h
new file mode 100644
index 0000000..bf56ebc
--- /dev/null
+++ b/sysdeps/linux-gnu/aarch64/signalent.h
@@ -0,0 +1,52 @@
+/*
+ * This file is part of ltrace.
+ * Copyright (C) 2006 Ian Wienand
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+	"SIG_0",			/* 0 */
+	"SIGHUP",			/* 1 */
+	"SIGINT",			/* 2 */
+	"SIGQUIT",			/* 3 */
+	"SIGILL",			/* 4 */
+	"SIGTRAP",			/* 5 */
+	"SIGABRT",			/* 6 */
+	"SIGBUS",			/* 7 */
+	"SIGFPE",			/* 8 */
+	"SIGKILL",			/* 9 */
+	"SIGUSR1",			/* 10 */
+	"SIGSEGV",			/* 11 */
+	"SIGUSR2",			/* 12 */
+	"SIGPIPE",			/* 13 */
+	"SIGALRM",			/* 14 */
+	"SIGTERM",			/* 15 */
+	"SIGSTKFLT",			/* 16 */
+	"SIGCHLD",			/* 17 */
+	"SIGCONT",			/* 18 */
+	"SIGSTOP",			/* 19 */
+	"SIGTSTP",			/* 20 */
+	"SIGTTIN",			/* 21 */
+	"SIGTTOU",			/* 22 */
+	"SIGURG",			/* 23 */
+	"SIGXCPU",			/* 24 */
+	"SIGXFSZ",			/* 25 */
+	"SIGVTALRM",			/* 26 */
+	"SIGPROF",			/* 27 */
+	"SIGWINCH",			/* 28 */
+	"SIGIO",			/* 29 */
+	"SIGPWR",			/* 30 */
+	"SIGSYS",			/* 31 */
diff --git a/sysdeps/linux-gnu/aarch64/syscallent.h b/sysdeps/linux-gnu/aarch64/syscallent.h
new file mode 100644
index 0000000..6187d1e
--- /dev/null
+++ b/sysdeps/linux-gnu/aarch64/syscallent.h
@@ -0,0 +1,21 @@
+/*
+ * This file is part of ltrace.
+ * Copyright (C) 2014 Petr Machata, Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+	"\0",			/* 0 */
diff --git a/sysdeps/linux-gnu/aarch64/trace.c b/sysdeps/linux-gnu/aarch64/trace.c
new file mode 100644
index 0000000..5544b51
--- /dev/null
+++ b/sysdeps/linux-gnu/aarch64/trace.c
@@ -0,0 +1,83 @@
+/*
+ * This file is part of ltrace.
+ * Copyright (C) 2014 Petr Machata, Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include <sys/ptrace.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <asm/ptrace.h>
+#include <string.h>
+#include <errno.h>
+
+#include "backend.h"
+#include "proc.h"
+
+void
+get_arch_dep(struct process *proc)
+{
+}
+
+int aarch64_read_gregs(struct process *proc, struct user_pt_regs *regs);
+
+/* The syscall instruction is:
+ * | 31                   21 | 20    5 | 4       0 |
+ * | 1 1 0 1 0 1 0 0 | 0 0 0 |  imm16  | 0 0 0 0 1 | */
+#define SVC_MASK  0xffe0001f
+#define SVC_VALUE 0xd4000001
+
+int
+syscall_p(struct process *proc, int status, int *sysnum)
+{
+	if (WIFSTOPPED(status)
+	    && WSTOPSIG(status) == (SIGTRAP | proc->tracesysgood)) {
+
+		struct user_pt_regs regs;
+		if (aarch64_read_gregs(proc, &regs) < 0) {
+			fprintf(stderr, "syscall_p: "
+				"Couldn't read registers of %d.\n", proc->pid);
+			return -1;
+		}
+
+		errno = 0;
+		unsigned long insn = (unsigned long) ptrace(PTRACE_PEEKTEXT,
+							    proc->pid,
+							    regs.pc - 4, 0);
+		if (insn == -1UL && errno != 0) {
+			fprintf(stderr, "syscall_p: "
+				"Couldn't peek into %d: %s\n", proc->pid,
+				strerror(errno));
+			return -1;
+		}
+
+		insn &= 0xffffffffUL;
+		if ((insn & SVC_MASK) == SVC_VALUE) {
+			*sysnum = regs.regs[8];
+
+			size_t d1 = proc->callstack_depth - 1;
+			if (proc->callstack_depth > 0
+			    && proc->callstack[d1].is_syscall
+			    && proc->callstack[d1].c_un.syscall == *sysnum)
+				return 2;
+
+			return 1;
+		}
+	}
+
+	return 0;
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/ltrace.git



More information about the ltrace-commits mailing list