From 76c51742c9e7ad8ab137e5dab1852798fc532207 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 6 Feb 2016 18:58:39 -0500 Subject: [PATCH] [mips64] Support for mips n64 Adding remaining mips n64 support including stackwalker. BUG=None TEST=manually tested on Linux/Android R=vapier@chromium.org Review URL: https://codereview.chromium.org/1418453011 . --- Makefile.am | 11 + Makefile.in | 75 ++ .../linux/dump_writer_common/thread_info.cc | 6 + .../dump_writer_common/ucontext_reader.cc | 6 + .../microdump_writer/microdump_writer.cc | 6 + .../linux/minidump_writer/minidump_writer.cc | 6 + src/common/android/include/sys/procfs.h | 4 +- .../common/minidump_cpu_mips.h | 16 + src/google_breakpad/common/minidump_format.h | 1 + src/processor/dump_context.cc | 9 +- src/processor/minidump.cc | 11 +- src/processor/minidump_processor.cc | 4 + src/processor/processor.gyp | 1 + src/processor/stackwalk_common.cc | 2 +- src/processor/stackwalker.cc | 1 + src/processor/stackwalker_mips.cc | 414 ++++++---- src/processor/stackwalker_mips64_unittest.cc | 719 ++++++++++++++++++ src/processor/stackwalker_mips_unittest.cc | 10 + src/tools/linux/md2core/minidump-2-core.cc | 14 +- 19 files changed, 1176 insertions(+), 140 deletions(-) create mode 100644 src/processor/stackwalker_mips64_unittest.cc diff --git a/Makefile.am b/Makefile.am index 47cd50ff..5136b1b4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -384,6 +384,7 @@ check_PROGRAMS += \ src/processor/stackwalker_arm64_unittest \ src/processor/stackwalker_address_list_unittest \ src/processor/stackwalker_mips_unittest \ + src/processor/stackwalker_mips64_unittest \ src/processor/stackwalker_x86_unittest \ src/processor/synth_minidump_unittest endif @@ -1052,6 +1053,16 @@ src_processor_stackwalker_mips_unittest_LDADD = \ src_processor_stackwalker_mips_unittest_CPPFLAGS = \ $(AM_CPPFLAGS) $(TEST_CFLAGS) +src_processor_stackwalker_mips64_unittest_SOURCES = \ + src/common/test_assembler.cc \ + src/processor/stackwalker_mips64_unittest.cc +src_processor_stackwalker_mips64_unittest_LDADD = \ + src/libbreakpad.a \ + $(TEST_LIBS) \ + $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) +src_processor_stackwalker_mips64_unittest_CPPFLAGS = \ + $(AM_CPPFLAGS) $(TEST_CFLAGS) + src_processor_stackwalker_x86_unittest_SOURCES = \ src/common/test_assembler.cc \ src/processor/stackwalker_x86_unittest.cc diff --git a/Makefile.in b/Makefile.in index 87441fcb..fbf6b042 100644 --- a/Makefile.in +++ b/Makefile.in @@ -200,6 +200,7 @@ EXTRA_PROGRAMS = $(am__EXEEXT_1) @DISABLE_PROCESSOR_FALSE@ src/processor/stackwalker_arm64_unittest \ @DISABLE_PROCESSOR_FALSE@ src/processor/stackwalker_address_list_unittest \ @DISABLE_PROCESSOR_FALSE@ src/processor/stackwalker_mips_unittest \ +@DISABLE_PROCESSOR_FALSE@ src/processor/stackwalker_mips64_unittest \ @DISABLE_PROCESSOR_FALSE@ src/processor/stackwalker_x86_unittest \ @DISABLE_PROCESSOR_FALSE@ src/processor/synth_minidump_unittest @@ -580,6 +581,7 @@ src_third_party_libdisasm_libdisasm_a_OBJECTS = \ @DISABLE_PROCESSOR_FALSE@ src/processor/stackwalker_arm64_unittest$(EXEEXT) \ @DISABLE_PROCESSOR_FALSE@ src/processor/stackwalker_address_list_unittest$(EXEEXT) \ @DISABLE_PROCESSOR_FALSE@ src/processor/stackwalker_mips_unittest$(EXEEXT) \ +@DISABLE_PROCESSOR_FALSE@ src/processor/stackwalker_mips64_unittest$(EXEEXT) \ @DISABLE_PROCESSOR_FALSE@ src/processor/stackwalker_x86_unittest$(EXEEXT) \ @DISABLE_PROCESSOR_FALSE@ src/processor/synth_minidump_unittest$(EXEEXT) @LINUX_HOST_TRUE@am__EXEEXT_7 = src/client/linux/linux_client_unittest$(EXEEXT) @@ -1207,6 +1209,18 @@ src_processor_stackwalker_arm_unittest_OBJECTS = \ @DISABLE_PROCESSOR_FALSE@ $(am__DEPENDENCIES_2) \ @DISABLE_PROCESSOR_FALSE@ $(am__DEPENDENCIES_1) \ @DISABLE_PROCESSOR_FALSE@ $(am__DEPENDENCIES_1) +am__src_processor_stackwalker_mips64_unittest_SOURCES_DIST = \ + src/common/test_assembler.cc \ + src/processor/stackwalker_mips64_unittest.cc +@DISABLE_PROCESSOR_FALSE@am_src_processor_stackwalker_mips64_unittest_OBJECTS = src/common/src_processor_stackwalker_mips64_unittest-test_assembler.$(OBJEXT) \ +@DISABLE_PROCESSOR_FALSE@ src/processor/src_processor_stackwalker_mips64_unittest-stackwalker_mips64_unittest.$(OBJEXT) +src_processor_stackwalker_mips64_unittest_OBJECTS = \ + $(am_src_processor_stackwalker_mips64_unittest_OBJECTS) +@DISABLE_PROCESSOR_FALSE@src_processor_stackwalker_mips64_unittest_DEPENDENCIES = \ +@DISABLE_PROCESSOR_FALSE@ src/libbreakpad.a \ +@DISABLE_PROCESSOR_FALSE@ $(am__DEPENDENCIES_2) \ +@DISABLE_PROCESSOR_FALSE@ $(am__DEPENDENCIES_1) \ +@DISABLE_PROCESSOR_FALSE@ $(am__DEPENDENCIES_1) am__src_processor_stackwalker_mips_unittest_SOURCES_DIST = \ src/common/test_assembler.cc \ src/processor/stackwalker_mips_unittest.cc @@ -1518,6 +1532,7 @@ SOURCES = $(src_client_linux_libbreakpad_client_a_SOURCES) \ $(src_processor_stackwalker_amd64_unittest_SOURCES) \ $(src_processor_stackwalker_arm64_unittest_SOURCES) \ $(src_processor_stackwalker_arm_unittest_SOURCES) \ + $(src_processor_stackwalker_mips64_unittest_SOURCES) \ $(src_processor_stackwalker_mips_unittest_SOURCES) \ $(src_processor_stackwalker_selftest_SOURCES) \ $(src_processor_stackwalker_x86_unittest_SOURCES) \ @@ -1566,6 +1581,7 @@ DIST_SOURCES = \ $(am__src_processor_stackwalker_amd64_unittest_SOURCES_DIST) \ $(am__src_processor_stackwalker_arm64_unittest_SOURCES_DIST) \ $(am__src_processor_stackwalker_arm_unittest_SOURCES_DIST) \ + $(am__src_processor_stackwalker_mips64_unittest_SOURCES_DIST) \ $(am__src_processor_stackwalker_mips_unittest_SOURCES_DIST) \ $(am__src_processor_stackwalker_selftest_SOURCES_DIST) \ $(am__src_processor_stackwalker_x86_unittest_SOURCES_DIST) \ @@ -2832,6 +2848,18 @@ TESTS = $(check_PROGRAMS) $(check_SCRIPTS) @DISABLE_PROCESSOR_FALSE@src_processor_stackwalker_mips_unittest_CPPFLAGS = \ @DISABLE_PROCESSOR_FALSE@ $(AM_CPPFLAGS) $(TEST_CFLAGS) +@DISABLE_PROCESSOR_FALSE@src_processor_stackwalker_mips64_unittest_SOURCES = \ +@DISABLE_PROCESSOR_FALSE@ src/common/test_assembler.cc \ +@DISABLE_PROCESSOR_FALSE@ src/processor/stackwalker_mips64_unittest.cc + +@DISABLE_PROCESSOR_FALSE@src_processor_stackwalker_mips64_unittest_LDADD = \ +@DISABLE_PROCESSOR_FALSE@ src/libbreakpad.a \ +@DISABLE_PROCESSOR_FALSE@ $(TEST_LIBS) \ +@DISABLE_PROCESSOR_FALSE@ $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) + +@DISABLE_PROCESSOR_FALSE@src_processor_stackwalker_mips64_unittest_CPPFLAGS = \ +@DISABLE_PROCESSOR_FALSE@ $(AM_CPPFLAGS) $(TEST_CFLAGS) + @DISABLE_PROCESSOR_FALSE@src_processor_stackwalker_x86_unittest_SOURCES = \ @DISABLE_PROCESSOR_FALSE@ src/common/test_assembler.cc \ @DISABLE_PROCESSOR_FALSE@ src/processor/stackwalker_x86_unittest.cc @@ -4073,6 +4101,16 @@ src/processor/src_processor_stackwalker_arm_unittest-stackwalker_arm_unittest.$( src/processor/stackwalker_arm_unittest$(EXEEXT): $(src_processor_stackwalker_arm_unittest_OBJECTS) $(src_processor_stackwalker_arm_unittest_DEPENDENCIES) $(EXTRA_src_processor_stackwalker_arm_unittest_DEPENDENCIES) src/processor/$(am__dirstamp) @rm -f src/processor/stackwalker_arm_unittest$(EXEEXT) $(AM_V_CXXLD)$(CXXLINK) $(src_processor_stackwalker_arm_unittest_OBJECTS) $(src_processor_stackwalker_arm_unittest_LDADD) $(LIBS) +src/common/src_processor_stackwalker_mips64_unittest-test_assembler.$(OBJEXT): \ + src/common/$(am__dirstamp) \ + src/common/$(DEPDIR)/$(am__dirstamp) +src/processor/src_processor_stackwalker_mips64_unittest-stackwalker_mips64_unittest.$(OBJEXT): \ + src/processor/$(am__dirstamp) \ + src/processor/$(DEPDIR)/$(am__dirstamp) + +src/processor/stackwalker_mips64_unittest$(EXEEXT): $(src_processor_stackwalker_mips64_unittest_OBJECTS) $(src_processor_stackwalker_mips64_unittest_DEPENDENCIES) $(EXTRA_src_processor_stackwalker_mips64_unittest_DEPENDENCIES) src/processor/$(am__dirstamp) + @rm -f src/processor/stackwalker_mips64_unittest$(EXEEXT) + $(AM_V_CXXLD)$(CXXLINK) $(src_processor_stackwalker_mips64_unittest_OBJECTS) $(src_processor_stackwalker_mips64_unittest_LDADD) $(LIBS) src/common/src_processor_stackwalker_mips_unittest-test_assembler.$(OBJEXT): \ src/common/$(am__dirstamp) \ src/common/$(DEPDIR)/$(am__dirstamp) @@ -4403,6 +4441,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@src/common/$(DEPDIR)/src_processor_stackwalker_amd64_unittest-test_assembler.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/common/$(DEPDIR)/src_processor_stackwalker_arm64_unittest-test_assembler.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/common/$(DEPDIR)/src_processor_stackwalker_arm_unittest-test_assembler.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@src/common/$(DEPDIR)/src_processor_stackwalker_mips64_unittest-test_assembler.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/common/$(DEPDIR)/src_processor_stackwalker_mips_unittest-test_assembler.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/common/$(DEPDIR)/src_processor_stackwalker_x86_unittest-test_assembler.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/common/$(DEPDIR)/src_processor_synth_minidump_unittest-test_assembler.Po@am__quote@ @@ -4541,6 +4580,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@src/processor/$(DEPDIR)/src_processor_stackwalker_amd64_unittest-stackwalker_amd64_unittest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/processor/$(DEPDIR)/src_processor_stackwalker_arm64_unittest-stackwalker_arm64_unittest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/processor/$(DEPDIR)/src_processor_stackwalker_arm_unittest-stackwalker_arm_unittest.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@src/processor/$(DEPDIR)/src_processor_stackwalker_mips64_unittest-stackwalker_mips64_unittest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/processor/$(DEPDIR)/src_processor_stackwalker_mips_unittest-stackwalker_mips_unittest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/processor/$(DEPDIR)/src_processor_stackwalker_x86_unittest-stackwalker_x86_unittest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/processor/$(DEPDIR)/src_processor_static_address_map_unittest-static_address_map_unittest.Po@am__quote@ @@ -6306,6 +6346,34 @@ src/processor/src_processor_stackwalker_arm_unittest-stackwalker_arm_unittest.ob @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_processor_stackwalker_arm_unittest_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/processor/src_processor_stackwalker_arm_unittest-stackwalker_arm_unittest.obj `if test -f 'src/processor/stackwalker_arm_unittest.cc'; then $(CYGPATH_W) 'src/processor/stackwalker_arm_unittest.cc'; else $(CYGPATH_W) '$(srcdir)/src/processor/stackwalker_arm_unittest.cc'; fi` +src/common/src_processor_stackwalker_mips64_unittest-test_assembler.o: src/common/test_assembler.cc +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_processor_stackwalker_mips64_unittest_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/common/src_processor_stackwalker_mips64_unittest-test_assembler.o -MD -MP -MF src/common/$(DEPDIR)/src_processor_stackwalker_mips64_unittest-test_assembler.Tpo -c -o src/common/src_processor_stackwalker_mips64_unittest-test_assembler.o `test -f 'src/common/test_assembler.cc' || echo '$(srcdir)/'`src/common/test_assembler.cc +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) src/common/$(DEPDIR)/src_processor_stackwalker_mips64_unittest-test_assembler.Tpo src/common/$(DEPDIR)/src_processor_stackwalker_mips64_unittest-test_assembler.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='src/common/test_assembler.cc' object='src/common/src_processor_stackwalker_mips64_unittest-test_assembler.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_processor_stackwalker_mips64_unittest_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/common/src_processor_stackwalker_mips64_unittest-test_assembler.o `test -f 'src/common/test_assembler.cc' || echo '$(srcdir)/'`src/common/test_assembler.cc + +src/common/src_processor_stackwalker_mips64_unittest-test_assembler.obj: src/common/test_assembler.cc +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_processor_stackwalker_mips64_unittest_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/common/src_processor_stackwalker_mips64_unittest-test_assembler.obj -MD -MP -MF src/common/$(DEPDIR)/src_processor_stackwalker_mips64_unittest-test_assembler.Tpo -c -o src/common/src_processor_stackwalker_mips64_unittest-test_assembler.obj `if test -f 'src/common/test_assembler.cc'; then $(CYGPATH_W) 'src/common/test_assembler.cc'; else $(CYGPATH_W) '$(srcdir)/src/common/test_assembler.cc'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) src/common/$(DEPDIR)/src_processor_stackwalker_mips64_unittest-test_assembler.Tpo src/common/$(DEPDIR)/src_processor_stackwalker_mips64_unittest-test_assembler.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='src/common/test_assembler.cc' object='src/common/src_processor_stackwalker_mips64_unittest-test_assembler.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_processor_stackwalker_mips64_unittest_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/common/src_processor_stackwalker_mips64_unittest-test_assembler.obj `if test -f 'src/common/test_assembler.cc'; then $(CYGPATH_W) 'src/common/test_assembler.cc'; else $(CYGPATH_W) '$(srcdir)/src/common/test_assembler.cc'; fi` + +src/processor/src_processor_stackwalker_mips64_unittest-stackwalker_mips64_unittest.o: src/processor/stackwalker_mips64_unittest.cc +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_processor_stackwalker_mips64_unittest_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/processor/src_processor_stackwalker_mips64_unittest-stackwalker_mips64_unittest.o -MD -MP -MF src/processor/$(DEPDIR)/src_processor_stackwalker_mips64_unittest-stackwalker_mips64_unittest.Tpo -c -o src/processor/src_processor_stackwalker_mips64_unittest-stackwalker_mips64_unittest.o `test -f 'src/processor/stackwalker_mips64_unittest.cc' || echo '$(srcdir)/'`src/processor/stackwalker_mips64_unittest.cc +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) src/processor/$(DEPDIR)/src_processor_stackwalker_mips64_unittest-stackwalker_mips64_unittest.Tpo src/processor/$(DEPDIR)/src_processor_stackwalker_mips64_unittest-stackwalker_mips64_unittest.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='src/processor/stackwalker_mips64_unittest.cc' object='src/processor/src_processor_stackwalker_mips64_unittest-stackwalker_mips64_unittest.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_processor_stackwalker_mips64_unittest_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/processor/src_processor_stackwalker_mips64_unittest-stackwalker_mips64_unittest.o `test -f 'src/processor/stackwalker_mips64_unittest.cc' || echo '$(srcdir)/'`src/processor/stackwalker_mips64_unittest.cc + +src/processor/src_processor_stackwalker_mips64_unittest-stackwalker_mips64_unittest.obj: src/processor/stackwalker_mips64_unittest.cc +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_processor_stackwalker_mips64_unittest_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/processor/src_processor_stackwalker_mips64_unittest-stackwalker_mips64_unittest.obj -MD -MP -MF src/processor/$(DEPDIR)/src_processor_stackwalker_mips64_unittest-stackwalker_mips64_unittest.Tpo -c -o src/processor/src_processor_stackwalker_mips64_unittest-stackwalker_mips64_unittest.obj `if test -f 'src/processor/stackwalker_mips64_unittest.cc'; then $(CYGPATH_W) 'src/processor/stackwalker_mips64_unittest.cc'; else $(CYGPATH_W) '$(srcdir)/src/processor/stackwalker_mips64_unittest.cc'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) src/processor/$(DEPDIR)/src_processor_stackwalker_mips64_unittest-stackwalker_mips64_unittest.Tpo src/processor/$(DEPDIR)/src_processor_stackwalker_mips64_unittest-stackwalker_mips64_unittest.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='src/processor/stackwalker_mips64_unittest.cc' object='src/processor/src_processor_stackwalker_mips64_unittest-stackwalker_mips64_unittest.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_processor_stackwalker_mips64_unittest_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/processor/src_processor_stackwalker_mips64_unittest-stackwalker_mips64_unittest.obj `if test -f 'src/processor/stackwalker_mips64_unittest.cc'; then $(CYGPATH_W) 'src/processor/stackwalker_mips64_unittest.cc'; else $(CYGPATH_W) '$(srcdir)/src/processor/stackwalker_mips64_unittest.cc'; fi` + src/common/src_processor_stackwalker_mips_unittest-test_assembler.o: src/common/test_assembler.cc @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_processor_stackwalker_mips_unittest_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/common/src_processor_stackwalker_mips_unittest-test_assembler.o -MD -MP -MF src/common/$(DEPDIR)/src_processor_stackwalker_mips_unittest-test_assembler.Tpo -c -o src/common/src_processor_stackwalker_mips_unittest-test_assembler.o `test -f 'src/common/test_assembler.cc' || echo '$(srcdir)/'`src/common/test_assembler.cc @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) src/common/$(DEPDIR)/src_processor_stackwalker_mips_unittest-test_assembler.Tpo src/common/$(DEPDIR)/src_processor_stackwalker_mips_unittest-test_assembler.Po @@ -7346,6 +7414,13 @@ src/processor/stackwalker_mips_unittest.log: src/processor/stackwalker_mips_unit --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) +src/processor/stackwalker_mips64_unittest.log: src/processor/stackwalker_mips64_unittest$(EXEEXT) + @p='src/processor/stackwalker_mips64_unittest$(EXEEXT)'; \ + b='src/processor/stackwalker_mips64_unittest'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) src/processor/stackwalker_x86_unittest.log: src/processor/stackwalker_x86_unittest$(EXEEXT) @p='src/processor/stackwalker_x86_unittest$(EXEEXT)'; \ b='src/processor/stackwalker_x86_unittest'; \ diff --git a/src/client/linux/dump_writer_common/thread_info.cc b/src/client/linux/dump_writer_common/thread_info.cc index 9956d445..0a1041d6 100644 --- a/src/client/linux/dump_writer_common/thread_info.cc +++ b/src/client/linux/dump_writer_common/thread_info.cc @@ -235,7 +235,13 @@ uintptr_t ThreadInfo::GetInstructionPointer() const { } void ThreadInfo::FillCPUContext(RawContextCPU* out) const { +#if _MIPS_SIM == _ABI64 + out->context_flags = MD_CONTEXT_MIPS64_FULL; +#elif _MIPS_SIM == _ABIO32 out->context_flags = MD_CONTEXT_MIPS_FULL; +#else +# error "This mips ABI is currently not supported (n32)" +#endif for (int i = 0; i < MD_CONTEXT_MIPS_GPR_COUNT; ++i) out->iregs[i] = mcontext.gregs[i]; diff --git a/src/client/linux/dump_writer_common/ucontext_reader.cc b/src/client/linux/dump_writer_common/ucontext_reader.cc index d37fdeb0..c80724dd 100644 --- a/src/client/linux/dump_writer_common/ucontext_reader.cc +++ b/src/client/linux/dump_writer_common/ucontext_reader.cc @@ -219,7 +219,13 @@ uintptr_t UContextReader::GetInstructionPointer(const struct ucontext* uc) { } void UContextReader::FillCPUContext(RawContextCPU *out, const ucontext *uc) { +#if _MIPS_SIM == _ABI64 + out->context_flags = MD_CONTEXT_MIPS64_FULL; +#elif _MIPS_SIM == _ABIO32 out->context_flags = MD_CONTEXT_MIPS_FULL; +#else +#error "This mips ABI is currently not supported (n32)" +#endif for (int i = 0; i < MD_CONTEXT_MIPS_GPR_COUNT; ++i) out->iregs[i] = uc->uc_mcontext.gregs[i]; diff --git a/src/client/linux/microdump_writer/microdump_writer.cc b/src/client/linux/microdump_writer/microdump_writer.cc index aa9f9413..fc29b714 100644 --- a/src/client/linux/microdump_writer/microdump_writer.cc +++ b/src/client/linux/microdump_writer/microdump_writer.cc @@ -179,7 +179,13 @@ class MicrodumpWriter { #elif defined(__i386__) const char kArch[] = "x86"; #elif defined(__mips__) +# if _MIPS_SIM == _ABIO32 const char kArch[] = "mips"; +# elif _MIPS_SIM == _ABI64 + const char kArch[] = "mips64"; +# else +# error "This mips ABI is currently not supported (n32)" +#endif #else #error "This code has not been ported to your platform yet" #endif diff --git a/src/client/linux/minidump_writer/minidump_writer.cc b/src/client/linux/minidump_writer/minidump_writer.cc index 0eed74de..9a0a830b 100644 --- a/src/client/linux/minidump_writer/minidump_writer.cc +++ b/src/client/linux/minidump_writer/minidump_writer.cc @@ -817,7 +817,13 @@ class MinidumpWriter { // processor_architecture should always be set, do this first sys_info->processor_architecture = #if defined(__mips__) +# if _MIPS_SIM == _ABIO32 MD_CPU_ARCHITECTURE_MIPS; +# elif _MIPS_SIM == _ABI64 + MD_CPU_ARCHITECTURE_MIPS64; +# else +# error "This mips ABI is currently not supported (n32)" +#endif #elif defined(__i386__) MD_CPU_ARCHITECTURE_X86; #else diff --git a/src/common/android/include/sys/procfs.h b/src/common/android/include/sys/procfs.h index 27223ea3..18512436 100644 --- a/src/common/android/include/sys/procfs.h +++ b/src/common/android/include/sys/procfs.h @@ -101,8 +101,8 @@ struct elf_prpsinfo { unsigned int pr_uid; unsigned int pr_gid; #elif defined(__mips__) - unsigned long pr_uid; - unsigned long pr_gid; + __kernel_uid_t pr_uid; + __kernel_gid_t pr_gid; #else unsigned short pr_uid; unsigned short pr_gid; diff --git a/src/google_breakpad/common/minidump_cpu_mips.h b/src/google_breakpad/common/minidump_cpu_mips.h index 6cbe3023..f4e2b589 100644 --- a/src/google_breakpad/common/minidump_cpu_mips.h +++ b/src/google_breakpad/common/minidump_cpu_mips.h @@ -157,4 +157,20 @@ enum MDMIPSRegisterNumbers { MD_CONTEXT_MIPS_FLOATING_POINT \ MD_CONTEXT_MIPS_DSP) +/** + * Breakpad defines for MIPS64 + */ +#define MD_CONTEXT_MIPS64 0x00080000 +#define MD_CONTEXT_MIPS64_INTEGER (MD_CONTEXT_MIPS64 | 0x00000002) +#define MD_CONTEXT_MIPS64_FLOATING_POINT (MD_CONTEXT_MIPS64 | 0x00000004) +#define MD_CONTEXT_MIPS64_DSP (MD_CONTEXT_MIPS64 | 0x00000008) + +#define MD_CONTEXT_MIPS64_FULL (MD_CONTEXT_MIPS64_INTEGER | \ + MD_CONTEXT_MIPS64_FLOATING_POINT | \ + MD_CONTEXT_MIPS64_DSP) + +#define MD_CONTEXT_MIPS64_ALL (MD_CONTEXT_MIPS64_INTEGER | \ + MD_CONTEXT_MIPS64_FLOATING_POINT \ + MD_CONTEXT_MIPS64_DSP) + #endif // GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_MIPS_H__ diff --git a/src/google_breakpad/common/minidump_format.h b/src/google_breakpad/common/minidump_format.h index 17a5abba..18f8268b 100644 --- a/src/google_breakpad/common/minidump_format.h +++ b/src/google_breakpad/common/minidump_format.h @@ -638,6 +638,7 @@ typedef enum { MD_CPU_ARCHITECTURE_SPARC = 0x8001, /* Breakpad-defined value for SPARC */ MD_CPU_ARCHITECTURE_PPC64 = 0x8002, /* Breakpad-defined value for PPC64 */ MD_CPU_ARCHITECTURE_ARM64 = 0x8003, /* Breakpad-defined value for ARM64 */ + MD_CPU_ARCHITECTURE_MIPS64 = 0x8004, /* Breakpad-defined value for MIPS64 */ MD_CPU_ARCHITECTURE_UNKNOWN = 0xffff /* PROCESSOR_ARCHITECTURE_UNKNOWN */ } MDCPUArchitecture; diff --git a/src/processor/dump_context.cc b/src/processor/dump_context.cc index 1c10b955..33b02cb6 100644 --- a/src/processor/dump_context.cc +++ b/src/processor/dump_context.cc @@ -131,7 +131,8 @@ const MDRawContextARM64* DumpContext::GetContextARM64() const { } const MDRawContextMIPS* DumpContext::GetContextMIPS() const { - if (GetContextCPU() != MD_CONTEXT_MIPS) { + if ((GetContextCPU() != MD_CONTEXT_MIPS) && + (GetContextCPU() != MD_CONTEXT_MIPS64)) { BPLOG(ERROR) << "DumpContext cannot get MIPS context"; return NULL; } @@ -172,6 +173,7 @@ bool DumpContext::GetInstructionPointer(uint64_t* ip) const { *ip = GetContextX86()->eip; break; case MD_CONTEXT_MIPS: + case MD_CONTEXT_MIPS64: *ip = GetContextMIPS()->epc; break; default: @@ -215,6 +217,7 @@ bool DumpContext::GetStackPointer(uint64_t* sp) const { *sp = GetContextX86()->esp; break; case MD_CONTEXT_MIPS: + case MD_CONTEXT_MIPS64: *sp = GetContextMIPS()->iregs[MD_CONTEXT_MIPS_REG_SP]; break; default: @@ -292,6 +295,7 @@ void DumpContext::FreeContext() { break; case MD_CONTEXT_MIPS: + case MD_CONTEXT_MIPS64: delete context_.ctx_mips; break; @@ -598,7 +602,8 @@ void DumpContext::Print() { break; } - case MD_CONTEXT_MIPS: { + case MD_CONTEXT_MIPS: + case MD_CONTEXT_MIPS64: { const MDRawContextMIPS* context_mips = GetContextMIPS(); printf("MDRawContextMIPS\n"); printf(" context_flags = 0x%x\n", diff --git a/src/processor/minidump.cc b/src/processor/minidump.cc index a23a0165..753c6df7 100644 --- a/src/processor/minidump.cc +++ b/src/processor/minidump.cc @@ -1009,7 +1009,8 @@ bool MinidumpContext::Read(uint32_t expected_size) { break; } - case MD_CONTEXT_MIPS: { + case MD_CONTEXT_MIPS: + case MD_CONTEXT_MIPS64: { if (expected_size != sizeof(MDRawContextMIPS)) { BPLOG(ERROR) << "MinidumpContext MIPS size mismatch, " << expected_size @@ -1157,6 +1158,11 @@ bool MinidumpContext::CheckAgainstSystemInfo(uint32_t context_cpu_type) { if (system_info_cpu_type == MD_CPU_ARCHITECTURE_MIPS) return_value = true; break; + + case MD_CONTEXT_MIPS64: + if (system_info_cpu_type == MD_CPU_ARCHITECTURE_MIPS64) + return_value = true; + break; } BPLOG_IF(ERROR, !return_value) << "MinidumpContext CPU " << @@ -4209,6 +4215,9 @@ bool Minidump::GetContextCPUFlagsFromSystemInfo(uint32_t *context_cpu_flags) { case MD_CPU_ARCHITECTURE_MIPS: *context_cpu_flags = MD_CONTEXT_MIPS; break; + case MD_CPU_ARCHITECTURE_MIPS64: + *context_cpu_flags = MD_CONTEXT_MIPS64; + break; case MD_CPU_ARCHITECTURE_ALPHA: *context_cpu_flags = MD_CONTEXT_ALPHA; break; diff --git a/src/processor/minidump_processor.cc b/src/processor/minidump_processor.cc index 78e98b8b..91468560 100644 --- a/src/processor/minidump_processor.cc +++ b/src/processor/minidump_processor.cc @@ -524,6 +524,10 @@ bool MinidumpProcessor::GetCPUInfo(Minidump *dump, SystemInfo *info) { info->cpu = "mips"; break; } + case MD_CPU_ARCHITECTURE_MIPS64: { + info->cpu = "mips64"; + break; + } default: { // Assign the numeric architecture ID into the CPU string. diff --git a/src/processor/processor.gyp b/src/processor/processor.gyp index 2c76925e..3ef23d51 100644 --- a/src/processor/processor.gyp +++ b/src/processor/processor.gyp @@ -160,6 +160,7 @@ 'stackwalker_arm64_unittest.cc', 'stackwalker_arm_unittest.cc', 'stackwalker_mips_unittest.cc', + 'stackwalker_mips64_unittest.cc', 'stackwalker_unittest_utils.h', 'stackwalker_x86_unittest.cc', 'static_address_map_unittest.cc', diff --git a/src/processor/stackwalk_common.cc b/src/processor/stackwalk_common.cc index 5cbcd27a..f5cf4802 100644 --- a/src/processor/stackwalk_common.cc +++ b/src/processor/stackwalk_common.cc @@ -546,7 +546,7 @@ static void PrintStack(const CallStack *stack, sequence = PrintRegister64("pc", frame_arm64->context.iregs[32], sequence); } - } else if (cpu == "mips") { + } else if ((cpu == "mips") || (cpu == "mips64")) { const StackFrameMIPS* frame_mips = reinterpret_cast(frame); diff --git a/src/processor/stackwalker.cc b/src/processor/stackwalker.cc index 94b66334..98cb0b5b 100644 --- a/src/processor/stackwalker.cc +++ b/src/processor/stackwalker.cc @@ -234,6 +234,7 @@ Stackwalker* Stackwalker::StackwalkerForCPU( break; case MD_CONTEXT_MIPS: + case MD_CONTEXT_MIPS64: cpu_stackwalker = new StackwalkerMIPS(system_info, context->GetContextMIPS(), memory, modules, frame_symbolizer); diff --git a/src/processor/stackwalker_mips.cc b/src/processor/stackwalker_mips.cc index 7db34219..db55d460 100644 --- a/src/processor/stackwalker_mips.cc +++ b/src/processor/stackwalker_mips.cc @@ -53,14 +53,25 @@ StackwalkerMIPS::StackwalkerMIPS(const SystemInfo* system_info, MemoryRegion* memory, const CodeModules* modules, StackFrameSymbolizer* resolver_helper) - : Stackwalker(system_info, memory, modules, resolver_helper), - context_(context) { - if (memory_ && memory_->GetBase() + memory_->GetSize() - 1 > 0xffffffff) { - BPLOG(ERROR) << "Memory out of range for stackwalking: " - << HexString(memory_->GetBase()) - << "+" - << HexString(memory_->GetSize()); - memory_ = NULL; +: Stackwalker(system_info, memory, modules, resolver_helper), + context_(context) { + if (context_->context_flags & MD_CONTEXT_MIPS64 ) { + if ((memory_ && memory_->GetBase() + memory_->GetSize() - 1) + > 0xffffffffffffffff) { + BPLOG(ERROR) << "Memory out of range for stackwalking mips64: " + << HexString(memory_->GetBase()) + << "+" + << HexString(memory_->GetSize()); + memory_ = NULL; + } + } else { + if ((memory_ && memory_->GetBase() + memory_->GetSize() - 1) > 0xffffffff) { + BPLOG(ERROR) << "Memory out of range for stackwalking mips32: " + << HexString(memory_->GetBase()) + << "+" + << HexString(memory_->GetSize()); + memory_ = NULL; + } } } @@ -96,73 +107,143 @@ StackFrameMIPS* StackwalkerMIPS::GetCallerByCFIFrameInfo( CFIFrameInfo* cfi_frame_info) { StackFrameMIPS* last_frame = static_cast(frames.back()); - uint32_t sp = 0, pc = 0; + if (context_->context_flags & MD_CONTEXT_MIPS) { + uint32_t sp = 0, pc = 0; - // Populate a dictionary with the valid register values in last_frame. - CFIFrameInfo::RegisterValueMap callee_registers; - // Use the STACK CFI data to recover the caller's register values. - CFIFrameInfo::RegisterValueMap caller_registers; + // Populate a dictionary with the valid register values in last_frame. + CFIFrameInfo::RegisterValueMap callee_registers; + // Use the STACK CFI data to recover the caller's register values. + CFIFrameInfo::RegisterValueMap caller_registers; - for (int i = 0; kRegisterNames[i]; ++i) { - caller_registers[kRegisterNames[i]] = last_frame->context.iregs[i]; - callee_registers[kRegisterNames[i]] = last_frame->context.iregs[i]; - } - - if (!cfi_frame_info->FindCallerRegs(callee_registers, *memory_, - &caller_registers)) { - return NULL; - } - - CFIFrameInfo::RegisterValueMap::const_iterator entry = - caller_registers.find(".cfa"); - - if (entry != caller_registers.end()) { - sp = entry->second; - caller_registers["$sp"] = entry->second; - } - - entry = caller_registers.find(".ra"); - if (entry != caller_registers.end()) { - caller_registers["$ra"] = entry->second; - pc = entry->second - 2 * sizeof(pc); - } - caller_registers["$pc"] = pc; - // Construct a new stack frame given the values the CFI recovered. - scoped_ptr frame(new StackFrameMIPS()); - - for (int i = 0; kRegisterNames[i]; ++i) { - CFIFrameInfo::RegisterValueMap::const_iterator caller_entry = - caller_registers.find(kRegisterNames[i]); - - if (caller_entry != caller_registers.end()) { - // The value of this register is recovered; fill the context with the - // value from caller_registers. - frame->context.iregs[i] = caller_entry->second; - frame->context_validity |= StackFrameMIPS::RegisterValidFlag(i); - } else if (((i >= INDEX_MIPS_REG_S0 && i <= INDEX_MIPS_REG_S7) || - (i > INDEX_MIPS_REG_GP && i < INDEX_MIPS_REG_RA)) && - (last_frame->context_validity & - StackFrameMIPS::RegisterValidFlag(i))) { - // If the STACK CFI data doesn't mention some callee-save register, and - // it is valid in the callee, assume the callee has not yet changed it. - // Calee-save registers according to the MIPS o32 ABI specification are: - // $s0 to $s7 - // $sp, $s8 - frame->context.iregs[i] = last_frame->context.iregs[i]; - frame->context_validity |= StackFrameMIPS::RegisterValidFlag(i); + for (int i = 0; kRegisterNames[i]; ++i) { + caller_registers[kRegisterNames[i]] = last_frame->context.iregs[i]; + callee_registers[kRegisterNames[i]] = last_frame->context.iregs[i]; } + + if (!cfi_frame_info->FindCallerRegs(callee_registers, *memory_, + &caller_registers)) { + return NULL; + } + + CFIFrameInfo::RegisterValueMap::const_iterator entry = + caller_registers.find(".cfa"); + + if (entry != caller_registers.end()) { + sp = entry->second; + caller_registers["$sp"] = entry->second; + } + + entry = caller_registers.find(".ra"); + if (entry != caller_registers.end()) { + caller_registers["$ra"] = entry->second; + pc = entry->second - 2 * sizeof(pc); + } + caller_registers["$pc"] = pc; + // Construct a new stack frame given the values the CFI recovered. + scoped_ptr frame(new StackFrameMIPS()); + + for (int i = 0; kRegisterNames[i]; ++i) { + CFIFrameInfo::RegisterValueMap::const_iterator caller_entry = + caller_registers.find(kRegisterNames[i]); + + if (caller_entry != caller_registers.end()) { + // The value of this register is recovered; fill the context with the + // value from caller_registers. + frame->context.iregs[i] = caller_entry->second; + frame->context_validity |= StackFrameMIPS::RegisterValidFlag(i); + } else if (((i >= INDEX_MIPS_REG_S0 && i <= INDEX_MIPS_REG_S7) || + (i > INDEX_MIPS_REG_GP && i < INDEX_MIPS_REG_RA)) && + (last_frame->context_validity & + StackFrameMIPS::RegisterValidFlag(i))) { + // If the STACK CFI data doesn't mention some callee-save register, and + // it is valid in the callee, assume the callee has not yet changed it. + // Calee-save registers according to the MIPS o32 ABI specification are: + // $s0 to $s7 + // $sp, $s8 + frame->context.iregs[i] = last_frame->context.iregs[i]; + frame->context_validity |= StackFrameMIPS::RegisterValidFlag(i); + } + } + + frame->context.epc = caller_registers["$pc"]; + frame->instruction = caller_registers["$pc"]; + frame->context_validity |= StackFrameMIPS::CONTEXT_VALID_PC; + + frame->context.iregs[MD_CONTEXT_MIPS_REG_RA] = caller_registers["$ra"]; + frame->context_validity |= StackFrameMIPS::CONTEXT_VALID_RA; + + frame->trust = StackFrame::FRAME_TRUST_CFI; + + return frame.release(); + } else { + uint64_t sp = 0, pc = 0; + + // Populate a dictionary with the valid register values in last_frame. + CFIFrameInfo::RegisterValueMap callee_registers; + // Use the STACK CFI data to recover the caller's register values. + CFIFrameInfo::RegisterValueMap caller_registers; + + for (int i = 0; kRegisterNames[i]; ++i) { + caller_registers[kRegisterNames[i]] = last_frame->context.iregs[i]; + callee_registers[kRegisterNames[i]] = last_frame->context.iregs[i]; + } + + if (!cfi_frame_info->FindCallerRegs(callee_registers, *memory_, + &caller_registers)) { + return NULL; + } + + CFIFrameInfo::RegisterValueMap::const_iterator entry = + caller_registers.find(".cfa"); + + if (entry != caller_registers.end()) { + sp = entry->second; + caller_registers["$sp"] = entry->second; + } + + entry = caller_registers.find(".ra"); + if (entry != caller_registers.end()) { + caller_registers["$ra"] = entry->second; + pc = entry->second - 2 * sizeof(pc); + } + caller_registers["$pc"] = pc; + // Construct a new stack frame given the values the CFI recovered. + scoped_ptr frame(new StackFrameMIPS()); + + for (int i = 0; kRegisterNames[i]; ++i) { + CFIFrameInfo::RegisterValueMap::const_iterator caller_entry = + caller_registers.find(kRegisterNames[i]); + + if (caller_entry != caller_registers.end()) { + // The value of this register is recovered; fill the context with the + // value from caller_registers. + frame->context.iregs[i] = caller_entry->second; + frame->context_validity |= StackFrameMIPS::RegisterValidFlag(i); + } else if (((i >= INDEX_MIPS_REG_S0 && i <= INDEX_MIPS_REG_S7) || + (i >= INDEX_MIPS_REG_GP && i < INDEX_MIPS_REG_RA)) && + (last_frame->context_validity & + StackFrameMIPS::RegisterValidFlag(i))) { + // If the STACK CFI data doesn't mention some callee-save register, and + // it is valid in the callee, assume the callee has not yet changed it. + // Calee-save registers according to the MIPS o32 ABI specification are: + // $s0 to $s7 + // $sp, $s8 + frame->context.iregs[i] = last_frame->context.iregs[i]; + frame->context_validity |= StackFrameMIPS::RegisterValidFlag(i); + } + } + + frame->context.epc = caller_registers["$pc"]; + frame->instruction = caller_registers["$pc"]; + frame->context_validity |= StackFrameMIPS::CONTEXT_VALID_PC; + + frame->context.iregs[MD_CONTEXT_MIPS_REG_RA] = caller_registers["$ra"]; + frame->context_validity |= StackFrameMIPS::CONTEXT_VALID_RA; + + frame->trust = StackFrame::FRAME_TRUST_CFI; + + return frame.release(); } - - frame->context.epc = caller_registers["$pc"]; - frame->instruction = caller_registers["$pc"]; - frame->context_validity |= StackFrameMIPS::CONTEXT_VALID_PC; - - frame->context.iregs[MD_CONTEXT_MIPS_REG_RA] = caller_registers["$ra"]; - frame->context_validity |= StackFrameMIPS::CONTEXT_VALID_RA; - - frame->trust = StackFrame::FRAME_TRUST_CFI; - - return frame.release(); } StackFrame* StackwalkerMIPS::GetCallerFrame(const CallStack* stack, @@ -204,7 +285,7 @@ StackFrame* StackwalkerMIPS::GetCallerFrame(const CallStack* stack, last_frame->context.iregs[MD_CONTEXT_MIPS_REG_SP]) { return NULL; } - + return new_frame.release(); } @@ -215,19 +296,20 @@ StackFrameMIPS* StackwalkerMIPS::GetCallerByStackScan( StackFrameMIPS* last_frame = static_cast(frames.back()); - uint32_t last_sp = last_frame->context.iregs[MD_CONTEXT_MIPS_REG_SP]; - uint32_t caller_pc, caller_sp, caller_fp; + if (context_->context_flags & MD_CONTEXT_MIPS) { + uint32_t last_sp = last_frame->context.iregs[MD_CONTEXT_MIPS_REG_SP]; + uint32_t caller_pc, caller_sp, caller_fp; - // Return address cannot be obtained directly. - // Force stackwalking. + // Return address cannot be obtained directly. + // Force stackwalking. - // We cannot use frame pointer to get the return address. - // We'll scan the stack for a - // return address. This can happen if last_frame is executing code - // for a module for which we don't have symbols. - int count = kMaxFrameStackSize / sizeof(caller_pc); + // We cannot use frame pointer to get the return address. + // We'll scan the stack for a + // return address. This can happen if last_frame is executing code + // for a module for which we don't have symbols. + int count = kMaxFrameStackSize / sizeof(caller_pc); - if (frames.size() > 1) { + if (frames.size() > 1) { // In case of mips32 ABI stack frame of a nonleaf function // must have minimum stack frame assigned for 4 arguments (4 words). // Move stack pointer for 4 words to avoid reporting non-existing frames @@ -235,65 +317,131 @@ StackFrameMIPS* StackwalkerMIPS::GetCallerByStackScan( // There is no way of knowing if topmost frame belongs to a leaf or // a nonleaf function. last_sp += kMinArgsOnStack * sizeof(caller_pc); - // Adjust 'count' so that return address is scanned only in limits + // Adjust 'count' so that return address is scanned only in limits // of one stack frame. count -= kMinArgsOnStack; - } - - do { - // Scanning for return address from stack pointer of the last frame. - if (!ScanForReturnAddress(last_sp, &caller_sp, &caller_pc, count)) { - // If we can't find an instruction pointer even with stack scanning, - // give up. - BPLOG(ERROR) << " ScanForReturnAddress failed "; - return NULL; } - // Get $fp stored in the stack frame. - if (!memory_->GetMemoryAtAddress(caller_sp - sizeof(caller_pc), - &caller_fp)) { - BPLOG(INFO) << " GetMemoryAtAddress for fp failed " ; + + do { + // Scanning for return address from stack pointer of the last frame. + if (!ScanForReturnAddress(last_sp, &caller_sp, &caller_pc, count)) { + // If we can't find an instruction pointer even with stack scanning, + // give up. + BPLOG(ERROR) << " ScanForReturnAddress failed "; + return NULL; + } + // Get $fp stored in the stack frame. + if (!memory_->GetMemoryAtAddress(caller_sp - sizeof(caller_pc), + &caller_fp)) { + BPLOG(INFO) << " GetMemoryAtAddress for fp failed " ; + return NULL; + } + + count = count - (caller_sp - last_sp) / sizeof(caller_pc); + // Now scan the next address in the stack. + last_sp = caller_sp + sizeof(caller_pc); + } while ((caller_fp - caller_sp >= kMaxFrameStackSize) && count > 0); + + if (!count) { + BPLOG(INFO) << " No frame found " ; return NULL; } - count = count - (caller_sp - last_sp) / sizeof(caller_pc); - // Now scan the next address in the stack. - last_sp = caller_sp + sizeof(caller_pc); - } while ((caller_fp - caller_sp >= kMaxFrameStackSize) && count > 0); + // ScanForReturnAddress found a reasonable return address. Advance + // $sp to the location above the one where the return address was + // found. + caller_sp += sizeof(caller_pc); + // caller_pc is actually containing $ra value; + // $pc is two instructions before $ra, + // so the caller_pc needs to be decremented accordingly. + caller_pc -= 2 * sizeof(caller_pc); - if (!count) { - BPLOG(INFO) << " No frame found " ; - return NULL; + // Create a new stack frame (ownership will be transferred to the caller) + // and fill it in. + StackFrameMIPS* frame = new StackFrameMIPS(); + frame->trust = StackFrame::FRAME_TRUST_SCAN; + frame->context = last_frame->context; + frame->context.epc = caller_pc; + frame->context_validity |= StackFrameMIPS::CONTEXT_VALID_PC; + frame->instruction = caller_pc; + + frame->context.iregs[MD_CONTEXT_MIPS_REG_SP] = caller_sp; + frame->context_validity |= StackFrameMIPS::CONTEXT_VALID_SP; + frame->context.iregs[MD_CONTEXT_MIPS_REG_FP] = caller_fp; + frame->context_validity |= StackFrameMIPS::CONTEXT_VALID_FP; + + frame->context.iregs[MD_CONTEXT_MIPS_REG_RA] = + caller_pc + 2 * sizeof(caller_pc); + frame->context_validity |= StackFrameMIPS::CONTEXT_VALID_RA; + + return frame; + } else { + uint64_t last_sp = last_frame->context.iregs[MD_CONTEXT_MIPS_REG_SP]; + uint64_t caller_pc, caller_sp, caller_fp; + + // Return address cannot be obtained directly. + // Force stackwalking. + + // We cannot use frame pointer to get the return address. + // We'll scan the stack for a + // return address. This can happen if last_frame is executing code + // for a module for which we don't have symbols. + int count = kMaxFrameStackSize / sizeof(caller_pc); + + do { + // Scanning for return address from stack pointer of the last frame. + if (!ScanForReturnAddress(last_sp, &caller_sp, &caller_pc, count)) { + // If we can't find an instruction pointer even with stack scanning, + // give up. + BPLOG(ERROR) << " ScanForReturnAddress failed "; + return NULL; + } + // Get $fp stored in the stack frame. + if (!memory_->GetMemoryAtAddress(caller_sp - sizeof(caller_pc), + &caller_fp)) { + BPLOG(INFO) << " GetMemoryAtAddress for fp failed " ; + return NULL; + } + + count = count - (caller_sp - last_sp) / sizeof(caller_pc); + // Now scan the next address in the stack. + last_sp = caller_sp + sizeof(caller_pc); + } while ((caller_fp - caller_sp >= kMaxFrameStackSize) && count > 0); + + if (!count) { + BPLOG(INFO) << " No frame found " ; + return NULL; + } + + // ScanForReturnAddress found a reasonable return address. Advance + // $sp to the location above the one where the return address was + // found. + caller_sp += sizeof(caller_pc); + // caller_pc is actually containing $ra value; + // $pc is two instructions before $ra, + // so the caller_pc needs to be decremented accordingly. + caller_pc -= 2 * sizeof(caller_pc); + + // Create a new stack frame (ownership will be transferred to the caller) + // and fill it in. + StackFrameMIPS* frame = new StackFrameMIPS(); + frame->trust = StackFrame::FRAME_TRUST_SCAN; + frame->context = last_frame->context; + frame->context.epc = caller_pc; + frame->context_validity |= StackFrameMIPS::CONTEXT_VALID_PC; + frame->instruction = caller_pc; + + frame->context.iregs[MD_CONTEXT_MIPS_REG_SP] = caller_sp; + frame->context_validity |= StackFrameMIPS::CONTEXT_VALID_SP; + frame->context.iregs[MD_CONTEXT_MIPS_REG_FP] = caller_fp; + frame->context_validity |= StackFrameMIPS::CONTEXT_VALID_FP; + + frame->context.iregs[MD_CONTEXT_MIPS_REG_RA] = + caller_pc + 2 * sizeof(caller_pc); + frame->context_validity |= StackFrameMIPS::CONTEXT_VALID_RA; + + return frame; } - - // ScanForReturnAddress found a reasonable return address. Advance - // $sp to the location above the one where the return address was - // found. - caller_sp += sizeof(caller_pc); - // caller_pc is actually containing $ra value; - // $pc is two instructions before $ra, - // so the caller_pc needs to be decremented accordingly. - caller_pc -= 2 * sizeof(caller_pc); - - - // Create a new stack frame (ownership will be transferred to the caller) - // and fill it in. - StackFrameMIPS* frame = new StackFrameMIPS(); - frame->trust = StackFrame::FRAME_TRUST_SCAN; - frame->context = last_frame->context; - frame->context.epc = caller_pc; - frame->context_validity |= StackFrameMIPS::CONTEXT_VALID_PC; - frame->instruction = caller_pc; - - frame->context.iregs[MD_CONTEXT_MIPS_REG_SP] = caller_sp; - frame->context_validity |= StackFrameMIPS::CONTEXT_VALID_SP; - frame->context.iregs[MD_CONTEXT_MIPS_REG_FP] = caller_fp; - frame->context_validity |= StackFrameMIPS::CONTEXT_VALID_FP; - - frame->context.iregs[MD_CONTEXT_MIPS_REG_RA] = - caller_pc + 2 * sizeof(caller_pc); - frame->context_validity |= StackFrameMIPS::CONTEXT_VALID_RA; - - return frame; } } // namespace google_breakpad diff --git a/src/processor/stackwalker_mips64_unittest.cc b/src/processor/stackwalker_mips64_unittest.cc new file mode 100644 index 00000000..531f546f --- /dev/null +++ b/src/processor/stackwalker_mips64_unittest.cc @@ -0,0 +1,719 @@ +// Copyright (c) 2013, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Original author: Veljko Mihailovic + +// stackwalker_mips64_unittest.cc: Unit tests for StackwalkerMIPS class for +// mips64 platforms. + +#include +#include +#include + +#include "breakpad_googletest_includes.h" +#include "common/test_assembler.h" +#include "common/using_std_string.h" +#include "google_breakpad/common/minidump_format.h" +#include "google_breakpad/processor/basic_source_line_resolver.h" +#include "google_breakpad/processor/call_stack.h" +#include "google_breakpad/processor/code_module.h" +#include "google_breakpad/processor/source_line_resolver_interface.h" +#include "google_breakpad/processor/stack_frame_cpu.h" +#include "processor/stackwalker_unittest_utils.h" +#include "processor/stackwalker_mips.h" +#include "processor/windows_frame_info.h" + +using google_breakpad::BasicSourceLineResolver; +using google_breakpad::CallStack; +using google_breakpad::CodeModule; +using google_breakpad::StackFrameSymbolizer; +using google_breakpad::StackFrame; +using google_breakpad::StackFrameMIPS; +using google_breakpad::Stackwalker; +using google_breakpad::StackwalkerMIPS; +using google_breakpad::SystemInfo; +using google_breakpad::WindowsFrameInfo; +using google_breakpad::test_assembler::kLittleEndian; +using google_breakpad::test_assembler::Label; +using google_breakpad::test_assembler::Section; +using std::vector; +using testing::_; +using testing::AnyNumber; +using testing::Return; +using testing::SetArgumentPointee; +using testing::Test; + +class StackwalkerMIPSFixture { + public: + StackwalkerMIPSFixture() + : stack_section(kLittleEndian), + // Give the two modules reasonable standard locations and names + // for tests to play with. + module1(0x00400000, 0x10000, "module1", "version1"), + module2(0x00500000, 0x10000, "module2", "version2") { + // Identify the system as a Linux system. + system_info.os = "Linux"; + system_info.os_short = "linux"; + system_info.os_version = "Observant Opossum"; // Jealous Jellyfish + system_info.cpu = "mips64"; + system_info.cpu_info = ""; + + // Put distinctive values in the raw CPU context. + BrandContext(&raw_context); + + // Create some modules with some stock debugging information. + modules.Add(&module1); + modules.Add(&module2); + + // By default, none of the modules have symbol info; call + // SetModuleSymbols to override this. + EXPECT_CALL(supplier, GetCStringSymbolData(_, _, _, _, _)) + .WillRepeatedly(Return(MockSymbolSupplier::NOT_FOUND)); + + // Avoid GMOCK WARNING "Uninteresting mock function call - returning + // directly" for FreeSymbolData(). + EXPECT_CALL(supplier, FreeSymbolData(_)).Times(AnyNumber()); + + // Reset max_frames_scanned since it's static. + Stackwalker::set_max_frames_scanned(1024); + } + + // Set the Breakpad symbol information that supplier should return for + // MODULE to INFO. + void SetModuleSymbols(MockCodeModule* module, const string& info) { + size_t buffer_size; + char* buffer = supplier.CopySymbolDataAndOwnTheCopy(info, &buffer_size); + EXPECT_CALL(supplier, GetCStringSymbolData(module, &system_info, _, _, _)) + .WillRepeatedly(DoAll(SetArgumentPointee<3>(buffer), + SetArgumentPointee<4>(buffer_size), + Return(MockSymbolSupplier::FOUND))); + } + + // Populate stack_region with the contents of stack_section. Use + // stack_section.start() as the region's starting address. + void RegionFromSection() { + string contents; + ASSERT_TRUE(stack_section.GetContents(&contents)); + stack_region.Init(stack_section.start().Value(), contents); + } + + // Fill RAW_CONTEXT with pseudo-random data, for round-trip checking. + void BrandContext(MDRawContextMIPS* raw_context) { + uint8_t x = 173; + for (size_t i = 0; i < sizeof(*raw_context); ++i) + reinterpret_cast(raw_context)[i] = (x += 17); + } + + SystemInfo system_info; + MDRawContextMIPS raw_context; + Section stack_section; + MockMemoryRegion stack_region; + MockCodeModule module1; + MockCodeModule module2; + MockCodeModules modules; + MockSymbolSupplier supplier; + BasicSourceLineResolver resolver; + CallStack call_stack; + const vector* frames; +}; + +class SanityCheck: public StackwalkerMIPSFixture, public Test { }; + +TEST_F(SanityCheck, NoResolver) { + raw_context.context_flags = + raw_context.context_flags | MD_CONTEXT_MIPS64_FULL; + stack_section.start() = 0x80000000; + stack_section.D64(0).D64(0x0); + RegionFromSection(); + raw_context.epc = 0x00400020; + raw_context.iregs[MD_CONTEXT_MIPS_REG_SP] = 0x80000000; + + StackFrameSymbolizer frame_symbolizer(NULL, NULL); + StackwalkerMIPS walker(&system_info, &raw_context, &stack_region, &modules, + &frame_symbolizer); + // This should succeed, even without a resolver or supplier. + vector modules_without_symbols; + vector modules_with_corrupt_symbols; + ASSERT_TRUE(walker.Walk(&call_stack, &modules_without_symbols, + &modules_with_corrupt_symbols)); + ASSERT_EQ(1U, modules_without_symbols.size()); + ASSERT_EQ("module1", modules_without_symbols[0]->debug_file()); + ASSERT_EQ(0U, modules_with_corrupt_symbols.size()); + frames = call_stack.frames(); + ASSERT_EQ(1U, frames->size()); + StackFrameMIPS* frame = static_cast(frames->at(0)); + // Check that the values from the original raw context made it + // through to the context in the stack frame. + EXPECT_EQ(0, memcmp(&raw_context, &frame->context, sizeof(raw_context))); +} + +class GetContextFrame: public StackwalkerMIPSFixture, public Test { }; + +TEST_F(GetContextFrame, Simple) { + raw_context.context_flags = + raw_context.context_flags | MD_CONTEXT_MIPS64_FULL; + stack_section.start() = 0x80000000; + stack_section.D64(0).D64(0x0); + RegionFromSection(); + raw_context.epc = 0x00400020; + raw_context.iregs[MD_CONTEXT_MIPS_REG_SP] = 0x80000000; + + StackFrameSymbolizer frame_symbolizer(&supplier, &resolver); + StackwalkerMIPS walker(&system_info, &raw_context, &stack_region, &modules, + &frame_symbolizer); + vector modules_without_symbols; + vector modules_with_corrupt_symbols; + ASSERT_TRUE(walker.Walk(&call_stack, &modules_without_symbols, + &modules_with_corrupt_symbols)); + ASSERT_EQ(1U, modules_without_symbols.size()); + ASSERT_EQ("module1", modules_without_symbols[0]->debug_file()); + ASSERT_EQ(0U, modules_with_corrupt_symbols.size()); + frames = call_stack.frames(); + StackFrameMIPS* frame = static_cast(frames->at(0)); + // Check that the values from the original raw context made it + // through to the context in the stack frame. + EXPECT_EQ(0, memcmp(&raw_context, &frame->context, sizeof(raw_context))); +} + +// The stackwalker should be able to produce the context frame even +// without stack memory present. +TEST_F(GetContextFrame, NoStackMemory) { + raw_context.context_flags = + raw_context.context_flags | MD_CONTEXT_MIPS64_FULL; + raw_context.epc = 0x00400020; + raw_context.iregs[MD_CONTEXT_MIPS_REG_SP] = 0x80000000; + + StackFrameSymbolizer frame_symbolizer(&supplier, &resolver); + StackwalkerMIPS walker(&system_info, &raw_context, NULL, &modules, + &frame_symbolizer); + vector modules_without_symbols; + vector modules_with_corrupt_symbols; + ASSERT_TRUE(walker.Walk(&call_stack, &modules_without_symbols, + &modules_with_corrupt_symbols)); + ASSERT_EQ(1U, modules_without_symbols.size()); + ASSERT_EQ("module1", modules_without_symbols[0]->debug_file()); + ASSERT_EQ(0U, modules_with_corrupt_symbols.size()); + frames = call_stack.frames(); + StackFrameMIPS* frame = static_cast(frames->at(0)); + // Check that the values from the original raw context made it + // through to the context in the stack frame. + EXPECT_EQ(0, memcmp(&raw_context, &frame->context, sizeof(raw_context))); +} + +class GetCallerFrame: public StackwalkerMIPSFixture, public Test { }; + +TEST_F(GetCallerFrame, ScanWithoutSymbols) { + raw_context.context_flags = + raw_context.context_flags | MD_CONTEXT_MIPS64_FULL; + // When the stack walker resorts to scanning the stack, + // only addresses located within loaded modules are + // considered valid return addresses. + // Force scanning through three frames to ensure that the + // stack pointer is set properly in scan-recovered frames. + stack_section.start() = 0x80000000; + uint64_t return_address1 = 0x00400100; + uint64_t return_address2 = 0x00400900; + Label frame1_sp, frame2_sp; + stack_section + // frame 0 + .Append(32, 0) // space + + .D64(0x00490000) // junk that's not + .D64(0x00600000) // a return address + + .D64(frame1_sp) // stack pointer + .D64(return_address1) // actual return address + // frame 1 + .Mark(&frame1_sp) + .Append(32, 0) // space + + .D64(0xF0000000) // more junk + .D64(0x0000000D) + + .D64(frame2_sp) // stack pointer + .D64(return_address2) // actual return address + // frame 2 + .Mark(&frame2_sp) + .Append(64, 0); // end of stack + RegionFromSection(); + + raw_context.epc = 0x00405510; + raw_context.iregs[MD_CONTEXT_MIPS_REG_SP] = stack_section.start().Value(); + raw_context.iregs[MD_CONTEXT_MIPS_REG_RA] = return_address1; + + StackFrameSymbolizer frame_symbolizer(&supplier, &resolver); + StackwalkerMIPS walker(&system_info, &raw_context, &stack_region, &modules, + &frame_symbolizer); + vector modules_without_symbols; + vector modules_with_corrupt_symbols; + ASSERT_TRUE(walker.Walk(&call_stack, &modules_without_symbols, + &modules_with_corrupt_symbols)); + ASSERT_EQ(1U, modules_without_symbols.size()); + ASSERT_EQ("module1", modules_without_symbols[0]->debug_file()); + ASSERT_EQ(0U, modules_with_corrupt_symbols.size()); + frames = call_stack.frames(); + ASSERT_EQ(3U, frames->size()); + + StackFrameMIPS* frame0 = static_cast(frames->at(0)); + EXPECT_EQ(StackFrame::FRAME_TRUST_CONTEXT, frame0->trust); + ASSERT_EQ(StackFrameMIPS::CONTEXT_VALID_ALL, frame0->context_validity); + EXPECT_EQ(0, memcmp(&raw_context, &frame0->context, sizeof(raw_context))); + + StackFrameMIPS* frame1 = static_cast(frames->at(1)); + EXPECT_EQ(StackFrame::FRAME_TRUST_SCAN, frame1->trust); + ASSERT_EQ((StackFrameMIPS::CONTEXT_VALID_PC | + StackFrameMIPS::CONTEXT_VALID_SP | + StackFrameMIPS::CONTEXT_VALID_FP | + StackFrameMIPS::CONTEXT_VALID_RA), + frame1->context_validity); + EXPECT_EQ(return_address1 - 2 * sizeof(return_address1), frame1->context.epc); + EXPECT_EQ(frame1_sp.Value(), frame1->context.iregs[MD_CONTEXT_MIPS_REG_SP]); + + StackFrameMIPS* frame2 = static_cast(frames->at(2)); + EXPECT_EQ(StackFrame::FRAME_TRUST_SCAN, frame2->trust); + ASSERT_EQ((StackFrameMIPS::CONTEXT_VALID_PC | + StackFrameMIPS::CONTEXT_VALID_SP | + StackFrameMIPS::CONTEXT_VALID_FP | + StackFrameMIPS::CONTEXT_VALID_RA), + frame2->context_validity); + EXPECT_EQ(return_address2 - 2 * sizeof(return_address2), frame2->context.epc); + EXPECT_EQ(frame2_sp.Value(), frame2->context.iregs[MD_CONTEXT_MIPS_REG_SP]); +} + +TEST_F(GetCallerFrame, ScanWithFunctionSymbols) { + raw_context.context_flags = + raw_context.context_flags | MD_CONTEXT_MIPS64_FULL; + // During stack scanning, if a potential return address + // is located within a loaded module that has symbols, + // it is only considered a valid return address if it + // lies within a function's bounds. + stack_section.start() = 0x80000000; + uint64_t return_address = 0x00500200; + Label frame1_sp; + stack_section + // frame 0 + .Append(16, 0) // space + + .D64(0x00490000) // junk that's not + .D64(0x00600000) // a return address + + .D64(0x00401000) // a couple of plausible addresses + .D64(0x0050F000) // that are not within functions + + .D64(frame1_sp) // stack pointer + .D64(return_address) // actual return address + // frame 1 + .Mark(&frame1_sp) + .Append(64, 0); // end of stack + RegionFromSection(); + + raw_context.epc = 0x00400200; + raw_context.iregs[MD_CONTEXT_MIPS_REG_SP] = stack_section.start().Value(); + raw_context.iregs[MD_CONTEXT_MIPS_REG_RA] = return_address; + + SetModuleSymbols(&module1, + // The youngest frame's function. + "FUNC 100 400 10 monotreme\n"); + SetModuleSymbols(&module2, + // The calling frame's function. + "FUNC 100 400 10 marsupial\n"); + + StackFrameSymbolizer frame_symbolizer(&supplier, &resolver); + StackwalkerMIPS walker(&system_info, &raw_context, &stack_region, &modules, + &frame_symbolizer); + vector modules_without_symbols; + vector modules_with_corrupt_symbols; + ASSERT_TRUE(walker.Walk(&call_stack, &modules_without_symbols, + &modules_with_corrupt_symbols)); + ASSERT_EQ(0U, modules_without_symbols.size()); + ASSERT_EQ(0U, modules_with_corrupt_symbols.size()); + frames = call_stack.frames(); + ASSERT_EQ(2U, frames->size()); + + StackFrameMIPS* frame0 = static_cast(frames->at(0)); + EXPECT_EQ(StackFrame::FRAME_TRUST_CONTEXT, frame0->trust); + ASSERT_EQ(StackFrameMIPS::CONTEXT_VALID_ALL, frame0->context_validity); + EXPECT_EQ(0, memcmp(&raw_context, &frame0->context, sizeof(raw_context))); + EXPECT_EQ("monotreme", frame0->function_name); + EXPECT_EQ(0x00400100U, frame0->function_base); + + StackFrameMIPS* frame1 = static_cast(frames->at(1)); + EXPECT_EQ(StackFrame::FRAME_TRUST_SCAN, frame1->trust); + ASSERT_EQ((StackFrameMIPS::CONTEXT_VALID_PC | + StackFrameMIPS::CONTEXT_VALID_SP | + StackFrameMIPS::CONTEXT_VALID_FP | + StackFrameMIPS::CONTEXT_VALID_RA), + frame1->context_validity); + EXPECT_EQ(return_address - 2 * sizeof(return_address), frame1->context.epc); + EXPECT_EQ(frame1_sp.Value(), frame1->context.iregs[MD_CONTEXT_MIPS_REG_SP]); + EXPECT_EQ("marsupial", frame1->function_name); + EXPECT_EQ(0x00500100U, frame1->function_base); +} + +TEST_F(GetCallerFrame, CheckStackFrameSizeLimit) { + raw_context.context_flags = + raw_context.context_flags | MD_CONTEXT_MIPS64_FULL; + // If the stackwalker resorts to stack scanning, it will scan only + // 1024 bytes of stack which correspondes to maximum size of stack frame. + stack_section.start() = 0x80000000; + uint64_t return_address1 = 0x00500100; + uint64_t return_address2 = 0x00500900; + Label frame1_sp, frame2_sp; + stack_section + // frame 0 + .Append(32, 0) // space + + .D64(0x00490000) // junk that's not + .D64(0x00600000) // a return address + + .Append(96, 0) // more space + + .D64(frame1_sp) // stack pointer + .D64(return_address1) // actual return address + // frame 1 + .Mark(&frame1_sp) + .Append(128 * 4, 0) // space + + .D64(0x00F00000) // more junk + .D64(0x0000000D) + + .Append(128 * 4, 0) // more space + + .D64(frame2_sp) // stack pointer + .D64(return_address2) // actual return address + // (won't be found) + // frame 2 + .Mark(&frame2_sp) + .Append(64, 0); // end of stack + RegionFromSection(); + + raw_context.epc = 0x00405510; + raw_context.iregs[MD_CONTEXT_MIPS_REG_SP] = stack_section.start().Value(); + raw_context.iregs[MD_CONTEXT_MIPS_REG_RA] = return_address1; + + StackFrameSymbolizer frame_symbolizer(&supplier, &resolver); + StackwalkerMIPS walker(&system_info, &raw_context, &stack_region, &modules, + &frame_symbolizer); + vector modules_without_symbols; + vector modules_with_corrupt_symbols; + ASSERT_TRUE(walker.Walk(&call_stack, &modules_without_symbols, + &modules_with_corrupt_symbols)); + ASSERT_EQ(2U, modules_without_symbols.size()); + ASSERT_EQ("module1", modules_without_symbols[0]->debug_file()); + ASSERT_EQ("module2", modules_without_symbols[1]->debug_file()); + ASSERT_EQ(0U, modules_with_corrupt_symbols.size()); + frames = call_stack.frames(); + ASSERT_EQ(2U, frames->size()); + + StackFrameMIPS* frame0 = static_cast(frames->at(0)); + EXPECT_EQ(StackFrame::FRAME_TRUST_CONTEXT, frame0->trust); + ASSERT_EQ(StackFrameMIPS::CONTEXT_VALID_ALL, frame0->context_validity); + EXPECT_EQ(0, memcmp(&raw_context, &frame0->context, sizeof(raw_context))); + + StackFrameMIPS* frame1 = static_cast(frames->at(1)); + EXPECT_EQ(StackFrame::FRAME_TRUST_SCAN, frame1->trust); + ASSERT_EQ((StackFrameMIPS::CONTEXT_VALID_PC | + StackFrameMIPS::CONTEXT_VALID_SP | + StackFrameMIPS::CONTEXT_VALID_FP | + StackFrameMIPS::CONTEXT_VALID_RA), + frame1->context_validity); + EXPECT_EQ(return_address1 - 2 * sizeof(return_address1), frame1->context.epc); + EXPECT_EQ(frame1_sp.Value(), frame1->context.iregs[MD_CONTEXT_MIPS_REG_SP]); +} + +// Test that set_max_frames_scanned prevents using stack scanning +// to find caller frames. +TEST_F(GetCallerFrame, ScanningNotAllowed) { + raw_context.context_flags = + raw_context.context_flags | MD_CONTEXT_MIPS64_FULL; + // When the stack walker resorts to scanning the stack, + // only fixed number of frames are allowed to be scanned out from stack + stack_section.start() = 0x80000000; + uint64_t return_address1 = 0x00500100; + uint64_t return_address2 = 0x00500900; + Label frame1_sp, frame2_sp; + stack_section + // frame 0 + .Append(32, 0) // space + + .D64(0x00490000) // junk that's not + .D64(0x00600000) // a return address + + .Append(96, 0) // more space + + .D64(frame1_sp) // stack pointer + .D64(return_address1) // actual return address + // frame 1 + .Mark(&frame1_sp) + .Append(128 * 4, 0) // space + + .D64(0x00F00000) // more junk + .D64(0x0000000D) + + .Append(128 * 4, 0) // more space + + .D64(frame2_sp) // stack pointer + .D64(return_address2) // actual return address + // (won't be found) + // frame 2 + .Mark(&frame2_sp) + .Append(64, 0); // end of stack + RegionFromSection(); + + raw_context.epc = 0x00405510; + raw_context.iregs[MD_CONTEXT_MIPS_REG_SP] = stack_section.start().Value(); + raw_context.iregs[MD_CONTEXT_MIPS_REG_RA] = return_address1; + + StackFrameSymbolizer frame_symbolizer(&supplier, &resolver); + StackwalkerMIPS walker(&system_info, &raw_context, &stack_region, &modules, + &frame_symbolizer); + Stackwalker::set_max_frames_scanned(0); + + vector modules_without_symbols; + vector modules_with_corrupt_symbols; + ASSERT_TRUE(walker.Walk(&call_stack, &modules_without_symbols, + &modules_with_corrupt_symbols)); + ASSERT_EQ(1U, modules_without_symbols.size()); + ASSERT_EQ("module1", modules_without_symbols[0]->debug_file()); + ASSERT_EQ(0U, modules_with_corrupt_symbols.size()); + frames = call_stack.frames(); + ASSERT_EQ(1U, frames->size()); + + StackFrameMIPS* frame0 = static_cast(frames->at(0)); + EXPECT_EQ(StackFrame::FRAME_TRUST_CONTEXT, frame0->trust); + ASSERT_EQ(StackFrameMIPS::CONTEXT_VALID_ALL, frame0->context_validity); + EXPECT_EQ(0, memcmp(&raw_context, &frame0->context, sizeof(raw_context))); +} + +struct CFIFixture: public StackwalkerMIPSFixture { + CFIFixture() { + // Provide some STACK CFI records; + SetModuleSymbols(&module1, + // The youngest frame's function. + "FUNC 4000 1000 0 enchiridion\n" + // Initially, nothing has been pushed on the stack, + // and the return address is still in the $ra register. + "STACK CFI INIT 4000 1000 .cfa: $sp 0 + .ra: $ra\n" + // Move stack pointer. + "STACK CFI 4004 .cfa: $sp 32 +\n" + // store $fp and ra + "STACK CFI 4008 $fp: .cfa -8 + ^ .ra: .cfa -4 + ^\n" + // restore $fp + "STACK CFI 400c .cfa: $fp 32 +\n" + // restore $sp + "STACK CFI 4018 .cfa: $sp 32 +\n" + + "STACK CFI 4020 $fp: $fp .cfa: $sp 0 + .ra: .ra\n" + + // The calling function. + "FUNC 5000 1000 0 epictetus\n" + // Initially, nothing has been pushed on the stack, + // and the return address is still in the $ra register. + "STACK CFI INIT 5000 1000 .cfa: $sp .ra: $ra\n" + // Mark it as end of stack. + "STACK CFI INIT 5000 8 .cfa: $sp 0 + .ra: $ra\n" + + // A function whose CFI makes the stack pointer + // go backwards. + "FUNC 6000 1000 20 palinal\n" + "STACK CFI INIT 6000 1000 .cfa: $sp 4 - .ra: $ra\n" + + // A function with CFI expressions that can't be + // evaluated. + "FUNC 7000 1000 20 rhetorical\n" + "STACK CFI INIT 7000 1000 .cfa: moot .ra: ambiguous\n" + ); + + // Provide some distinctive values for the caller's registers. + expected.epc = 0x00405500; + expected.iregs[MD_CONTEXT_MIPS_REG_S0] = 0x0; + expected.iregs[MD_CONTEXT_MIPS_REG_S1] = 0x1; + expected.iregs[MD_CONTEXT_MIPS_REG_S2] = 0x2; + expected.iregs[MD_CONTEXT_MIPS_REG_S3] = 0x3; + expected.iregs[MD_CONTEXT_MIPS_REG_S4] = 0x4; + expected.iregs[MD_CONTEXT_MIPS_REG_S5] = 0x5; + expected.iregs[MD_CONTEXT_MIPS_REG_S6] = 0x6; + expected.iregs[MD_CONTEXT_MIPS_REG_S7] = 0x7; + expected.iregs[MD_CONTEXT_MIPS_REG_SP] = 0x80000000; + expected.iregs[MD_CONTEXT_MIPS_REG_FP] = 0x80000000; + expected.iregs[MD_CONTEXT_MIPS_REG_RA] = 0x00405510; + + // Expect CFI to recover all callee-save registers. Since CFI is the + // only stack frame construction technique we have, aside from the + // context frame itself, there's no way for us to have a set of valid + // registers smaller than this. + expected_validity = (StackFrameMIPS::CONTEXT_VALID_PC | + StackFrameMIPS::CONTEXT_VALID_S0 | + StackFrameMIPS::CONTEXT_VALID_S1 | + StackFrameMIPS::CONTEXT_VALID_S2 | + StackFrameMIPS::CONTEXT_VALID_S3 | + StackFrameMIPS::CONTEXT_VALID_S4 | + StackFrameMIPS::CONTEXT_VALID_S5 | + StackFrameMIPS::CONTEXT_VALID_S6 | + StackFrameMIPS::CONTEXT_VALID_S7 | + StackFrameMIPS::CONTEXT_VALID_SP | + StackFrameMIPS::CONTEXT_VALID_FP | + StackFrameMIPS::CONTEXT_VALID_GP | + StackFrameMIPS::CONTEXT_VALID_RA); + + // By default, context frames provide all registers, as normal. + context_frame_validity = StackFrameMIPS::CONTEXT_VALID_ALL; + + // By default, registers are unchanged. + raw_context = expected; + } + + // Walk the stack, using stack_section as the contents of the stack + // and raw_context as the current register values. (Set the stack + // pointer to the stack's starting address.) Expect two stack + // frames; in the older frame, expect the callee-saves registers to + // have values matching those in 'expected'. + void CheckWalk() { + RegionFromSection(); + raw_context.iregs[MD_CONTEXT_MIPS_REG_SP] = stack_section.start().Value(); + + StackFrameSymbolizer frame_symbolizer(&supplier, &resolver); + StackwalkerMIPS walker(&system_info, &raw_context, &stack_region, + &modules, &frame_symbolizer); + vector modules_without_symbols; + vector modules_with_corrupt_symbols; + ASSERT_TRUE(walker.Walk(&call_stack, &modules_without_symbols, + &modules_with_corrupt_symbols)); + ASSERT_EQ(0U, modules_without_symbols.size()); + ASSERT_EQ(0U, modules_with_corrupt_symbols.size()); + frames = call_stack.frames(); + ASSERT_EQ(2U, frames->size()); + + StackFrameMIPS* frame0 = static_cast(frames->at(0)); + EXPECT_EQ(StackFrame::FRAME_TRUST_CONTEXT, frame0->trust); + ASSERT_EQ(StackFrameMIPS::CONTEXT_VALID_ALL, frame0->context_validity); + EXPECT_EQ("enchiridion", frame0->function_name); + EXPECT_EQ(0x00404000U, frame0->function_base); + + StackFrameMIPS* frame1 = static_cast(frames->at(1)); + EXPECT_EQ(StackFrame::FRAME_TRUST_CFI, frame1->trust); + ASSERT_EQ(expected_validity, frame1->context_validity); + EXPECT_EQ(expected.iregs[MD_CONTEXT_MIPS_REG_S0], + frame1->context.iregs[MD_CONTEXT_MIPS_REG_S0]); + EXPECT_EQ(expected.iregs[MD_CONTEXT_MIPS_REG_S1], + frame1->context.iregs[MD_CONTEXT_MIPS_REG_S1]); + EXPECT_EQ(expected.iregs[MD_CONTEXT_MIPS_REG_S2], + frame1->context.iregs[MD_CONTEXT_MIPS_REG_S2]); + EXPECT_EQ(expected.iregs[MD_CONTEXT_MIPS_REG_S3], + frame1->context.iregs[MD_CONTEXT_MIPS_REG_S3]); + EXPECT_EQ(expected.iregs[MD_CONTEXT_MIPS_REG_S4], + frame1->context.iregs[MD_CONTEXT_MIPS_REG_S4]); + EXPECT_EQ(expected.iregs[MD_CONTEXT_MIPS_REG_S5], + frame1->context.iregs[MD_CONTEXT_MIPS_REG_S5]); + EXPECT_EQ(expected.iregs[MD_CONTEXT_MIPS_REG_S6], + frame1->context.iregs[MD_CONTEXT_MIPS_REG_S6]); + EXPECT_EQ(expected.iregs[MD_CONTEXT_MIPS_REG_S7], + frame1->context.iregs[MD_CONTEXT_MIPS_REG_S7]); + EXPECT_EQ(expected.iregs[MD_CONTEXT_MIPS_REG_FP], + frame1->context.iregs[MD_CONTEXT_MIPS_REG_FP]); + EXPECT_EQ(expected.iregs[MD_CONTEXT_MIPS_REG_RA], + frame1->context.iregs[MD_CONTEXT_MIPS_REG_RA]); + EXPECT_EQ(expected.iregs[MD_CONTEXT_MIPS_REG_SP], + frame1->context.iregs[MD_CONTEXT_MIPS_REG_SP]); + EXPECT_EQ(expected.epc, frame1->context.epc); + EXPECT_EQ(expected.epc, frame1->instruction); + EXPECT_EQ("epictetus", frame1->function_name); + EXPECT_EQ(0x00405000U, frame1->function_base); + } + + // The values we expect to find for the caller's registers. + MDRawContextMIPS expected; + + // The validity mask for expected. + int expected_validity; + + // The validity mask to impose on the context frame. + int context_frame_validity; +}; + +class CFI: public CFIFixture, public Test { }; + +// TODO(gordanac): add CFI tests + +TEST_F(CFI, At4004) { + raw_context.context_flags = + raw_context.context_flags | MD_CONTEXT_MIPS64_FULL; + Label frame1_sp = expected.iregs[MD_CONTEXT_MIPS_REG_SP]; + stack_section + // frame0 + .Append(16, 0) // space + .D64(frame1_sp) // stack pointer + .D64(0x00405510) // return address + .Mark(&frame1_sp); // This effectively sets stack_section.start(). + raw_context.epc = 0x00404004; + CheckWalk(); +} + +// Check that we reject rules that would cause the stack pointer to +// move in the wrong direction. +TEST_F(CFI, RejectBackwards) { + raw_context.context_flags = + raw_context.context_flags | MD_CONTEXT_MIPS64_FULL; + raw_context.epc = 0x40005000; + raw_context.iregs[MD_CONTEXT_MIPS_REG_SP] = 0x80000000; + raw_context.iregs[MD_CONTEXT_MIPS_REG_RA] = 0x00405510; + + StackFrameSymbolizer frame_symbolizer(&supplier, &resolver); + StackwalkerMIPS walker(&system_info, &raw_context, &stack_region, &modules, + &frame_symbolizer); + vector modules_without_symbols; + vector modules_with_corrupt_symbols; + ASSERT_TRUE(walker.Walk(&call_stack, &modules_without_symbols, + &modules_with_corrupt_symbols)); + ASSERT_EQ(0U, modules_without_symbols.size()); + ASSERT_EQ(0U, modules_with_corrupt_symbols.size()); + frames = call_stack.frames(); + ASSERT_EQ(1U, frames->size()); +} + +// Check that we reject rules whose expressions' evaluation fails. +TEST_F(CFI, RejectBadExpressions) { + raw_context.context_flags = + raw_context.context_flags | MD_CONTEXT_MIPS64_FULL; + raw_context.epc = 0x00407000; + raw_context.iregs[MD_CONTEXT_MIPS_REG_SP] = 0x80000000; + raw_context.iregs[MD_CONTEXT_MIPS_REG_RA] = 0x00405510; + + StackFrameSymbolizer frame_symbolizer(&supplier, &resolver); + StackwalkerMIPS walker(&system_info, &raw_context, &stack_region, &modules, + &frame_symbolizer); + vector modules_without_symbols; + vector modules_with_corrupt_symbols; + ASSERT_TRUE(walker.Walk(&call_stack, &modules_without_symbols, + &modules_with_corrupt_symbols)); + ASSERT_EQ(0U, modules_without_symbols.size()); + ASSERT_EQ(0U, modules_with_corrupt_symbols.size()); + frames = call_stack.frames(); + ASSERT_EQ(1U, frames->size()); +} diff --git a/src/processor/stackwalker_mips_unittest.cc b/src/processor/stackwalker_mips_unittest.cc index ed4be4f5..5398c2b3 100644 --- a/src/processor/stackwalker_mips_unittest.cc +++ b/src/processor/stackwalker_mips_unittest.cc @@ -145,6 +145,7 @@ class StackwalkerMIPSFixture { class SanityCheck: public StackwalkerMIPSFixture, public Test { }; TEST_F(SanityCheck, NoResolver) { + raw_context.context_flags = raw_context.context_flags | MD_CONTEXT_MIPS_FULL; stack_section.start() = 0x80000000; stack_section.D32(0).D32(0x0); RegionFromSection(); @@ -173,6 +174,7 @@ TEST_F(SanityCheck, NoResolver) { class GetContextFrame: public StackwalkerMIPSFixture, public Test { }; TEST_F(GetContextFrame, Simple) { + raw_context.context_flags = raw_context.context_flags | MD_CONTEXT_MIPS_FULL; stack_section.start() = 0x80000000; stack_section.D32(0).D32(0x0); RegionFromSection(); @@ -199,6 +201,7 @@ TEST_F(GetContextFrame, Simple) { // The stackwalker should be able to produce the context frame even // without stack memory present. TEST_F(GetContextFrame, NoStackMemory) { + raw_context.context_flags = raw_context.context_flags | MD_CONTEXT_MIPS_FULL; raw_context.epc = 0x00400020; raw_context.iregs[MD_CONTEXT_MIPS_REG_SP] = 0x80000000; @@ -222,6 +225,7 @@ TEST_F(GetContextFrame, NoStackMemory) { class GetCallerFrame: public StackwalkerMIPSFixture, public Test { }; TEST_F(GetCallerFrame, ScanWithoutSymbols) { + raw_context.context_flags = raw_context.context_flags | MD_CONTEXT_MIPS_FULL; // When the stack walker resorts to scanning the stack, // only addresses located within loaded modules are // considered valid return addresses. @@ -298,6 +302,7 @@ TEST_F(GetCallerFrame, ScanWithoutSymbols) { } TEST_F(GetCallerFrame, ScanWithFunctionSymbols) { + raw_context.context_flags = raw_context.context_flags | MD_CONTEXT_MIPS_FULL; // During stack scanning, if a potential return address // is located within a loaded module that has symbols, // it is only considered a valid return address if it @@ -366,6 +371,7 @@ TEST_F(GetCallerFrame, ScanWithFunctionSymbols) { } TEST_F(GetCallerFrame, CheckStackFrameSizeLimit) { + raw_context.context_flags = raw_context.context_flags | MD_CONTEXT_MIPS_FULL; // If the stackwalker resorts to stack scanning, it will scan only // 1024 bytes of stack which correspondes to maximum size of stack frame. stack_section.start() = 0x80000000; @@ -437,6 +443,7 @@ TEST_F(GetCallerFrame, CheckStackFrameSizeLimit) { // Test that set_max_frames_scanned prevents using stack scanning // to find caller frames. TEST_F(GetCallerFrame, ScanningNotAllowed) { + raw_context.context_flags = raw_context.context_flags | MD_CONTEXT_MIPS_FULL; // When the stack walker resorts to scanning the stack, // only fixed number of frames are allowed to be scanned out from stack stack_section.start() = 0x80000000; @@ -646,6 +653,7 @@ class CFI: public CFIFixture, public Test { }; // TODO(gordanac): add CFI tests TEST_F(CFI, At4004) { + raw_context.context_flags = raw_context.context_flags | MD_CONTEXT_MIPS_FULL; Label frame1_sp = expected.iregs[MD_CONTEXT_MIPS_REG_SP]; stack_section // frame0 @@ -660,6 +668,7 @@ TEST_F(CFI, At4004) { // Check that we reject rules that would cause the stack pointer to // move in the wrong direction. TEST_F(CFI, RejectBackwards) { + raw_context.context_flags = raw_context.context_flags | MD_CONTEXT_MIPS_FULL; raw_context.epc = 0x40005000; raw_context.iregs[MD_CONTEXT_MIPS_REG_SP] = 0x80000000; raw_context.iregs[MD_CONTEXT_MIPS_REG_RA] = 0x00405510; @@ -679,6 +688,7 @@ TEST_F(CFI, RejectBackwards) { // Check that we reject rules whose expressions' evaluation fails. TEST_F(CFI, RejectBadExpressions) { + raw_context.context_flags = raw_context.context_flags | MD_CONTEXT_MIPS_FULL; raw_context.epc = 0x00407000; raw_context.iregs[MD_CONTEXT_MIPS_REG_SP] = 0x80000000; raw_context.iregs[MD_CONTEXT_MIPS_REG_RA] = 0x00405510; diff --git a/src/tools/linux/md2core/minidump-2-core.cc b/src/tools/linux/md2core/minidump-2-core.cc index 102ce677..322bbad6 100644 --- a/src/tools/linux/md2core/minidump-2-core.cc +++ b/src/tools/linux/md2core/minidump-2-core.cc @@ -494,11 +494,21 @@ ParseSystemInfo(CrashedProcess* crashinfo, const MinidumpMemoryRange& range, _exit(1); } #elif defined(__mips__) +# if _MIPS_SIM == _ABIO32 if (sysinfo->processor_architecture != MD_CPU_ARCHITECTURE_MIPS) { fprintf(stderr, - "This version of minidump-2-core only supports mips (32bit).\n"); + "This version of minidump-2-core only supports mips o32 (32bit).\n"); _exit(1); } +# elif _MIPS_SIM == _ABI64 + if (sysinfo->processor_architecture != MD_CPU_ARCHITECTURE_MIPS64) { + fprintf(stderr, + "This version of minidump-2-core only supports mips n64 (64bit).\n"); + _exit(1); + } +# else +# error "This mips ABI is currently not supported (n32)" +# endif #else #error "This code has not been ported to your platform yet" #endif @@ -525,6 +535,8 @@ ParseSystemInfo(CrashedProcess* crashinfo, const MinidumpMemoryRange& range, ? "ARM" : sysinfo->processor_architecture == MD_CPU_ARCHITECTURE_MIPS ? "MIPS" + : sysinfo->processor_architecture == MD_CPU_ARCHITECTURE_MIPS64 + ? "MIPS64" : "???", sysinfo->number_of_processors, sysinfo->processor_level,