Initial implementation of minidump reader (#6). r=bryner

git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@11 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
mmentovai 2006-09-06 02:56:44 +00:00
parent 07f8ef56ac
commit 3261e8b6ea
14 changed files with 11135 additions and 3403 deletions

View file

@ -18,6 +18,7 @@
# This allows #includes to be relative to src/ # This allows #includes to be relative to src/
AM_CPPFLAGS = -I$(top_srcdir)/src AM_CPPFLAGS = -I$(top_srcdir)/src
## Documentation ## Documentation
docdir = $(prefix)/share/doc/$(PACKAGE)-$(VERSION) docdir = $(prefix)/share/doc/$(PACKAGE)-$(VERSION)
@ -34,14 +35,34 @@ dist_doc_DATA = \
lib_LTLIBRARIES = src/libairbag.la lib_LTLIBRARIES = src/libairbag.la
src_libairbag_la_SOURCES = \ src_libairbag_la_SOURCES = \
src/google/airbag_types.h \
src/google/crash_report.h \
src/google/stack_frame.h \
src/processor/memory_region.h \
src/processor/minidump.cc \
src/processor/minidump.h \
src/processor/minidump_format.h \
src/processor/range_map.h \
src/processor/source_line_resolver.cc \ src/processor/source_line_resolver.cc \
src/processor/source_line_resolver.h src/processor/source_line_resolver.h
## Programs
bin_PROGRAMS = \
src/processor/minidump_dump
## Tests ## Tests
TESTS = src/processor/source_line_resolver_unittest check_PROGRAMS = \
src/processor/range_map_unittest \
src/processor/source_line_resolver_unittest
check_SCRIPTS = \
src/processor/minidump_dump_test
TESTS = $(check_PROGRAMS) $(check_SCRIPTS)
TESTS_ENVIRONMENT = TESTS_ENVIRONMENT =
check_SCRIPTS =
src_processor_range_map_unittest_SOURCES = \
src/processor/range_map_unittest.cc
src_processor_source_line_resolver_unittest_SOURCES = \ src_processor_source_line_resolver_unittest_SOURCES = \
src/processor/source_line_resolver_unittest.cc src/processor/source_line_resolver_unittest.cc
@ -50,13 +71,20 @@ src_processor_source_line_resolver_unittest_LDADD = \
## Non-installables ## Non-installables
noinst_PROGRAMS = $(TESTS) noinst_PROGRAMS =
noinst_SCRIPTS = $(check_SCRIPTS) noinst_SCRIPTS = $(check_SCRIPTS)
src_processor_minidump_dump_SOURCES = \
src/processor/minidump_dump.cc
src_processor_minidump_dump_LDADD = \
src/processor/minidump.lo
## Additional files to be included in a source distribution ## Additional files to be included in a source distribution
EXTRA_DIST = \ EXTRA_DIST = \
$(SCRIPTS) \ $(SCRIPTS) \
src/processor/testdata/minidump1.dmp \
src/processor/testdata/minidump1.out \
src/processor/testdata/module1.out \ src/processor/testdata/module1.out \
src/processor/testdata/module2.out \ src/processor/testdata/module2.out \
src/processor/testdata/module3_bad.out src/processor/testdata/module3_bad.out

View file

@ -1,4 +1,4 @@
# Makefile.in generated by automake 1.9.5 from Makefile.am. # Makefile.in generated by automake 1.9.6 from Makefile.am.
# @configure_input@ # @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@ -31,8 +31,6 @@
SOURCES = $(src_libairbag_la_SOURCES) $(src_processor_source_line_resolver_unittest_SOURCES)
srcdir = @srcdir@ srcdir = @srcdir@
top_srcdir = @top_srcdir@ top_srcdir = @top_srcdir@
VPATH = @srcdir@ VPATH = @srcdir@
@ -55,7 +53,10 @@ PRE_UNINSTALL = :
POST_UNINSTALL = : POST_UNINSTALL = :
build_triplet = @build@ build_triplet = @build@
host_triplet = @host@ host_triplet = @host@
noinst_PROGRAMS = $(am__EXEEXT_1) bin_PROGRAMS = src/processor/minidump_dump$(EXEEXT)
check_PROGRAMS = src/processor/range_map_unittest$(EXEEXT) \
src/processor/source_line_resolver_unittest$(EXEEXT)
noinst_PROGRAMS =
DIST_COMMON = README $(am__configure_deps) $(dist_doc_DATA) \ DIST_COMMON = README $(am__configure_deps) $(dist_doc_DATA) \
$(srcdir)/Makefile.am $(srcdir)/Makefile.in \ $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
$(top_srcdir)/configure $(top_srcdir)/src/config.h.in AUTHORS \ $(top_srcdir)/configure $(top_srcdir)/src/config.h.in AUTHORS \
@ -78,15 +79,27 @@ am__vpath_adj = case $$p in \
*) f=$$p;; \ *) f=$$p;; \
esac; esac;
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(docdir)" am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \
"$(DESTDIR)$(docdir)"
libLTLIBRARIES_INSTALL = $(INSTALL) libLTLIBRARIES_INSTALL = $(INSTALL)
LTLIBRARIES = $(lib_LTLIBRARIES) LTLIBRARIES = $(lib_LTLIBRARIES)
src_libairbag_la_LIBADD = src_libairbag_la_LIBADD =
am__dirstamp = $(am__leading_dot)dirstamp am__dirstamp = $(am__leading_dot)dirstamp
am_src_libairbag_la_OBJECTS = src/processor/source_line_resolver.lo am_src_libairbag_la_OBJECTS = src/processor/minidump.lo \
src/processor/source_line_resolver.lo
src_libairbag_la_OBJECTS = $(am_src_libairbag_la_OBJECTS) src_libairbag_la_OBJECTS = $(am_src_libairbag_la_OBJECTS)
am__EXEEXT_1 = src/processor/source_line_resolver_unittest$(EXEEXT) binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
PROGRAMS = $(noinst_PROGRAMS) PROGRAMS = $(bin_PROGRAMS) $(noinst_PROGRAMS)
am_src_processor_minidump_dump_OBJECTS = \
src/processor/minidump_dump.$(OBJEXT)
src_processor_minidump_dump_OBJECTS = \
$(am_src_processor_minidump_dump_OBJECTS)
src_processor_minidump_dump_DEPENDENCIES = src/processor/minidump.lo
am_src_processor_range_map_unittest_OBJECTS = \
src/processor/range_map_unittest.$(OBJEXT)
src_processor_range_map_unittest_OBJECTS = \
$(am_src_processor_range_map_unittest_OBJECTS)
src_processor_range_map_unittest_LDADD = $(LDADD)
am_src_processor_source_line_resolver_unittest_OBJECTS = \ am_src_processor_source_line_resolver_unittest_OBJECTS = \
src/processor/source_line_resolver_unittest.$(OBJEXT) src/processor/source_line_resolver_unittest.$(OBJEXT)
src_processor_source_line_resolver_unittest_OBJECTS = \ src_processor_source_line_resolver_unittest_OBJECTS = \
@ -114,8 +127,12 @@ CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@ $(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = $(src_libairbag_la_SOURCES) \ SOURCES = $(src_libairbag_la_SOURCES) \
$(src_processor_minidump_dump_SOURCES) \
$(src_processor_range_map_unittest_SOURCES) \
$(src_processor_source_line_resolver_unittest_SOURCES) $(src_processor_source_line_resolver_unittest_SOURCES)
DIST_SOURCES = $(src_libairbag_la_SOURCES) \ DIST_SOURCES = $(src_libairbag_la_SOURCES) \
$(src_processor_minidump_dump_SOURCES) \
$(src_processor_range_map_unittest_SOURCES) \
$(src_processor_source_line_resolver_unittest_SOURCES) $(src_processor_source_line_resolver_unittest_SOURCES)
dist_docDATA_INSTALL = $(INSTALL_DATA) dist_docDATA_INSTALL = $(INSTALL_DATA)
DATA = $(dist_doc_DATA) DATA = $(dist_doc_DATA)
@ -243,12 +260,25 @@ dist_doc_DATA = \
lib_LTLIBRARIES = src/libairbag.la lib_LTLIBRARIES = src/libairbag.la
src_libairbag_la_SOURCES = \ src_libairbag_la_SOURCES = \
src/google/airbag_types.h \
src/google/crash_report.h \
src/google/stack_frame.h \
src/processor/memory_region.h \
src/processor/minidump.cc \
src/processor/minidump.h \
src/processor/minidump_format.h \
src/processor/range_map.h \
src/processor/source_line_resolver.cc \ src/processor/source_line_resolver.cc \
src/processor/source_line_resolver.h src/processor/source_line_resolver.h
TESTS = src/processor/source_line_resolver_unittest check_SCRIPTS = \
src/processor/minidump_dump_test
TESTS = $(check_PROGRAMS) $(check_SCRIPTS)
TESTS_ENVIRONMENT = TESTS_ENVIRONMENT =
check_SCRIPTS = src_processor_range_map_unittest_SOURCES = \
src/processor/range_map_unittest.cc
src_processor_source_line_resolver_unittest_SOURCES = \ src_processor_source_line_resolver_unittest_SOURCES = \
src/processor/source_line_resolver_unittest.cc src/processor/source_line_resolver_unittest.cc
@ -256,8 +286,16 @@ src_processor_source_line_resolver_unittest_LDADD = \
src/processor/source_line_resolver.lo src/processor/source_line_resolver.lo
noinst_SCRIPTS = $(check_SCRIPTS) noinst_SCRIPTS = $(check_SCRIPTS)
src_processor_minidump_dump_SOURCES = \
src/processor/minidump_dump.cc
src_processor_minidump_dump_LDADD = \
src/processor/minidump.lo
EXTRA_DIST = \ EXTRA_DIST = \
$(SCRIPTS) \ $(SCRIPTS) \
src/processor/testdata/minidump1.dmp \
src/processor/testdata/minidump1.out \
src/processor/testdata/module1.out \ src/processor/testdata/module1.out \
src/processor/testdata/module2.out \ src/processor/testdata/module2.out \
src/processor/testdata/module3_bad.out src/processor/testdata/module3_bad.out
@ -349,6 +387,8 @@ src/processor/$(am__dirstamp):
src/processor/$(DEPDIR)/$(am__dirstamp): src/processor/$(DEPDIR)/$(am__dirstamp):
@$(mkdir_p) src/processor/$(DEPDIR) @$(mkdir_p) src/processor/$(DEPDIR)
@: > src/processor/$(DEPDIR)/$(am__dirstamp) @: > src/processor/$(DEPDIR)/$(am__dirstamp)
src/processor/minidump.lo: src/processor/$(am__dirstamp) \
src/processor/$(DEPDIR)/$(am__dirstamp)
src/processor/source_line_resolver.lo: src/processor/$(am__dirstamp) \ src/processor/source_line_resolver.lo: src/processor/$(am__dirstamp) \
src/processor/$(DEPDIR)/$(am__dirstamp) src/processor/$(DEPDIR)/$(am__dirstamp)
src/$(am__dirstamp): src/$(am__dirstamp):
@ -356,6 +396,41 @@ src/$(am__dirstamp):
@: > src/$(am__dirstamp) @: > src/$(am__dirstamp)
src/libairbag.la: $(src_libairbag_la_OBJECTS) $(src_libairbag_la_DEPENDENCIES) src/$(am__dirstamp) src/libairbag.la: $(src_libairbag_la_OBJECTS) $(src_libairbag_la_DEPENDENCIES) src/$(am__dirstamp)
$(CXXLINK) -rpath $(libdir) $(src_libairbag_la_LDFLAGS) $(src_libairbag_la_OBJECTS) $(src_libairbag_la_LIBADD) $(LIBS) $(CXXLINK) -rpath $(libdir) $(src_libairbag_la_LDFLAGS) $(src_libairbag_la_OBJECTS) $(src_libairbag_la_LIBADD) $(LIBS)
install-binPROGRAMS: $(bin_PROGRAMS)
@$(NORMAL_INSTALL)
test -z "$(bindir)" || $(mkdir_p) "$(DESTDIR)$(bindir)"
@list='$(bin_PROGRAMS)'; for p in $$list; do \
p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
if test -f $$p \
|| test -f $$p1 \
; then \
f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \
$(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \
else :; fi; \
done
uninstall-binPROGRAMS:
@$(NORMAL_UNINSTALL)
@list='$(bin_PROGRAMS)'; for p in $$list; do \
f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
rm -f "$(DESTDIR)$(bindir)/$$f"; \
done
clean-binPROGRAMS:
@list='$(bin_PROGRAMS)'; for p in $$list; do \
f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
echo " rm -f $$p $$f"; \
rm -f $$p $$f ; \
done
clean-checkPROGRAMS:
@list='$(check_PROGRAMS)'; for p in $$list; do \
f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
echo " rm -f $$p $$f"; \
rm -f $$p $$f ; \
done
clean-noinstPROGRAMS: clean-noinstPROGRAMS:
@list='$(noinst_PROGRAMS)'; for p in $$list; do \ @list='$(noinst_PROGRAMS)'; for p in $$list; do \
@ -363,6 +438,17 @@ clean-noinstPROGRAMS:
echo " rm -f $$p $$f"; \ echo " rm -f $$p $$f"; \
rm -f $$p $$f ; \ rm -f $$p $$f ; \
done done
src/processor/minidump_dump.$(OBJEXT): src/processor/$(am__dirstamp) \
src/processor/$(DEPDIR)/$(am__dirstamp)
src/processor/minidump_dump$(EXEEXT): $(src_processor_minidump_dump_OBJECTS) $(src_processor_minidump_dump_DEPENDENCIES) src/processor/$(am__dirstamp)
@rm -f src/processor/minidump_dump$(EXEEXT)
$(CXXLINK) $(src_processor_minidump_dump_LDFLAGS) $(src_processor_minidump_dump_OBJECTS) $(src_processor_minidump_dump_LDADD) $(LIBS)
src/processor/range_map_unittest.$(OBJEXT): \
src/processor/$(am__dirstamp) \
src/processor/$(DEPDIR)/$(am__dirstamp)
src/processor/range_map_unittest$(EXEEXT): $(src_processor_range_map_unittest_OBJECTS) $(src_processor_range_map_unittest_DEPENDENCIES) src/processor/$(am__dirstamp)
@rm -f src/processor/range_map_unittest$(EXEEXT)
$(CXXLINK) $(src_processor_range_map_unittest_LDFLAGS) $(src_processor_range_map_unittest_OBJECTS) $(src_processor_range_map_unittest_LDADD) $(LIBS)
src/processor/source_line_resolver_unittest.$(OBJEXT): \ src/processor/source_line_resolver_unittest.$(OBJEXT): \
src/processor/$(am__dirstamp) \ src/processor/$(am__dirstamp) \
src/processor/$(DEPDIR)/$(am__dirstamp) src/processor/$(DEPDIR)/$(am__dirstamp)
@ -372,6 +458,10 @@ src/processor/source_line_resolver_unittest$(EXEEXT): $(src_processor_source_lin
mostlyclean-compile: mostlyclean-compile:
-rm -f *.$(OBJEXT) -rm -f *.$(OBJEXT)
-rm -f src/processor/minidump.$(OBJEXT)
-rm -f src/processor/minidump.lo
-rm -f src/processor/minidump_dump.$(OBJEXT)
-rm -f src/processor/range_map_unittest.$(OBJEXT)
-rm -f src/processor/source_line_resolver.$(OBJEXT) -rm -f src/processor/source_line_resolver.$(OBJEXT)
-rm -f src/processor/source_line_resolver.lo -rm -f src/processor/source_line_resolver.lo
-rm -f src/processor/source_line_resolver_unittest.$(OBJEXT) -rm -f src/processor/source_line_resolver_unittest.$(OBJEXT)
@ -379,6 +469,9 @@ mostlyclean-compile:
distclean-compile: distclean-compile:
-rm -f *.tab.c -rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@src/processor/$(DEPDIR)/minidump.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/processor/$(DEPDIR)/minidump_dump.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/processor/$(DEPDIR)/range_map_unittest.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/processor/$(DEPDIR)/source_line_resolver.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/processor/$(DEPDIR)/source_line_resolver.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/processor/$(DEPDIR)/source_line_resolver_unittest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/processor/$(DEPDIR)/source_line_resolver_unittest.Po@am__quote@
@ -559,7 +652,7 @@ check-TESTS: $(TESTS)
distdir: $(DISTFILES) distdir: $(DISTFILES)
$(am__remove_distdir) $(am__remove_distdir)
mkdir $(distdir) mkdir $(distdir)
$(mkdir_p) $(distdir)/autotools $(distdir)/src $(distdir)/src/processor/testdata $(mkdir_p) $(distdir)/autotools $(distdir)/src $(distdir)/src/processor $(distdir)/src/processor/testdata
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
list='$(DISTFILES)'; for file in $$list; do \ list='$(DISTFILES)'; for file in $$list; do \
@ -684,12 +777,14 @@ distcleancheck: distclean
$(distcleancheck_listfiles) ; \ $(distcleancheck_listfiles) ; \
exit 1; } >&2 exit 1; } >&2
check-am: all-am check-am: all-am
$(MAKE) $(AM_MAKEFLAGS) $(check_SCRIPTS) $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) $(check_SCRIPTS)
$(MAKE) $(AM_MAKEFLAGS) check-TESTS $(MAKE) $(AM_MAKEFLAGS) check-TESTS
check: check-am check: check-am
all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(SCRIPTS) $(DATA) all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(SCRIPTS) $(DATA)
install-binPROGRAMS: install-libLTLIBRARIES
installdirs: installdirs:
for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(docdir)"; do \ for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(docdir)"; do \
test -z "$$dir" || $(mkdir_p) "$$dir"; \ test -z "$$dir" || $(mkdir_p) "$$dir"; \
done done
install: install-am install: install-am
@ -721,8 +816,9 @@ maintainer-clean-generic:
@echo "it deletes files that may require special tools to rebuild." @echo "it deletes files that may require special tools to rebuild."
clean: clean-am clean: clean-am
clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \ clean-am: clean-binPROGRAMS clean-checkPROGRAMS clean-generic \
clean-noinstPROGRAMS mostlyclean-am clean-libLTLIBRARIES clean-libtool clean-noinstPROGRAMS \
mostlyclean-am
distclean: distclean-am distclean: distclean-am
-rm -f $(am__CONFIG_DISTCLEAN_FILES) -rm -f $(am__CONFIG_DISTCLEAN_FILES)
@ -743,7 +839,7 @@ info-am:
install-data-am: install-dist_docDATA install-data-am: install-dist_docDATA
install-exec-am: install-libLTLIBRARIES install-exec-am: install-binPROGRAMS install-libLTLIBRARIES
install-info: install-info-am install-info: install-info-am
@ -771,24 +867,25 @@ ps: ps-am
ps-am: ps-am:
uninstall-am: uninstall-dist_docDATA uninstall-info-am \ uninstall-am: uninstall-binPROGRAMS uninstall-dist_docDATA \
uninstall-libLTLIBRARIES uninstall-info-am uninstall-libLTLIBRARIES
.PHONY: CTAGS GTAGS all all-am am--refresh check check-TESTS check-am \ .PHONY: CTAGS GTAGS all all-am am--refresh check check-TESTS check-am \
clean clean-generic clean-libLTLIBRARIES clean-libtool \ clean clean-binPROGRAMS clean-checkPROGRAMS clean-generic \
clean-noinstPROGRAMS ctags dist dist-all dist-bzip2 dist-gzip \ clean-libLTLIBRARIES clean-libtool clean-noinstPROGRAMS ctags \
dist-shar dist-tarZ dist-zip distcheck distclean \ dist dist-all dist-bzip2 dist-gzip dist-shar dist-tarZ \
distclean-compile distclean-generic distclean-hdr \ dist-zip distcheck distclean distclean-compile \
distclean-libtool distclean-tags distcleancheck distdir \ distclean-generic distclean-hdr distclean-libtool \
distuninstallcheck dvi dvi-am html html-am info info-am \ distclean-tags distcleancheck distdir distuninstallcheck dvi \
install install-am install-data install-data-am \ dvi-am html html-am info info-am install install-am \
install-binPROGRAMS install-data install-data-am \
install-dist_docDATA install-exec install-exec-am install-info \ install-dist_docDATA install-exec install-exec-am install-info \
install-info-am install-libLTLIBRARIES install-man \ install-info-am install-libLTLIBRARIES install-man \
install-strip installcheck installcheck-am installdirs \ install-strip installcheck installcheck-am installdirs \
maintainer-clean maintainer-clean-generic mostlyclean \ maintainer-clean maintainer-clean-generic mostlyclean \
mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
pdf pdf-am ps ps-am tags uninstall uninstall-am \ pdf pdf-am ps ps-am tags uninstall uninstall-am \
uninstall-dist_docDATA uninstall-info-am \ uninstall-binPROGRAMS uninstall-dist_docDATA uninstall-info-am \
uninstall-libLTLIBRARIES uninstall-libLTLIBRARIES

1621
aclocal.m4 vendored

File diff suppressed because it is too large Load diff

5048
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,65 @@
// Copyright (C) 2006 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// memory_region.h: Access to memory regions.
//
// A MemoryRegion provides virtual access to a range of memory. It is an
// abstraction allowing the actual source of memory to be independent of
// methods which need to access a virtual memory space.
//
// Author: Mark Mentovai
#ifndef PROCESSOR_MEMORY_REGION_H__
#define PROCESSOR_MEMORY_REGION_H__
#include "google/airbag_types.h"
namespace google_airbag {
class MemoryRegion {
public:
virtual ~MemoryRegion() {}
// The base address of this memory region.
virtual u_int64_t GetBase() = 0;
// The size of this memory region.
virtual u_int32_t GetSize() = 0;
// Access to data of various sizes within the memory region. address
// is a pointer to read, and it must lie within the memory region as
// defined by its base address and size. The location pointed to by
// value is set to the value at address. Byte-swapping is performed
// if necessary so that the value is appropriate for the running
// program. Returns true on success. Fails and returns false if address
// is out of the region's bounds (after considering the width of value),
// or for other types of errors.
virtual bool GetMemoryAtAddress(u_int64_t address,
u_int8_t* value) = 0;
virtual bool GetMemoryAtAddress(u_int64_t address,
u_int16_t* value) = 0;
virtual bool GetMemoryAtAddress(u_int64_t address,
u_int32_t* value) = 0;
virtual bool GetMemoryAtAddress(u_int64_t address,
u_int64_t* value) = 0;
};
} // namespace google_airbag
#endif // PROCESSOR_MEMORY_REGION_H__

2025
src/processor/minidump.cc Normal file

File diff suppressed because it is too large Load diff

699
src/processor/minidump.h Normal file
View file

@ -0,0 +1,699 @@
// Copyright (C) 2006 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// minidump.h: A minidump reader.
//
// The basic structure of this module tracks the structure of the minidump
// file itself. At the top level, a minidump file is represented by a
// Minidump object. Like most other classes in this module, Minidump
// provides a Read method that initializes the object with information from
// the file. Most of the classes in this file are wrappers around the
// "raw" structures found in the minidump file itself, and defined in
// minidump_format.h. For example, each thread is represented by a
// MinidumpThread object, whose parameters are specified in an MDRawThread
// structure. A properly byte-swapped MDRawThread can be obtained from a
// MinidumpThread easily by calling its thread() method.
//
// Most of the module lazily reads only the portion of the minidump file
// necessary to fulfill the user's request. Calling Minidump::Read
// only reads the minidump's directory. The thread list is not read until
// it is needed, and even once it's read, the memory regions for each
// thread's stack aren't read until they're needed. This strategy avoids
// unnecessary file input, and allocating memory for data in which the user
// has no interest. Note that although memory allocations for a typical
// minidump file are not particularly large, it is possible for legitimate
// minidumps to be sizable. A full-memory minidump, for example, contains
// a snapshot of the entire mapped memory space. Even a normal minidump,
// with stack memory only, can be large if, for example, the dump was
// generated in response to a crash that occurred due to an infinite-
// recursion bug that caused the stack's limits to be exceeded. Finally,
// some users of this library will unfortunately find themselves in the
// position of having to process potentially-hostile minidumps that might
// attempt to cause problems by forcing the minidump processor to over-
// allocate memory.
//
// Memory management in this module is based on a strict
// you-don't-own-anything policy. The only object owned by the user is
// the top-level Minidump object, the creation and destruction of which
// must be the user's own responsibility. All other objects obtained
// through interaction with this module are ultimately owned by the
// Minidump object, and will be freed upon the Minidump object's destruction.
// Because memory regions can potentially involve large allocations, a
// FreeMemory method is provided by MinidumpMemoryRegion, allowing the user
// to release data when it is no longer needed. Use of this method is
// optional but recommended. If freed data is later required, it will
// be read back in from the minidump file again.
//
// There is one exception to this memory management policy:
// Minidump::ReadString will return a string object to the user, and the user
// is responsible for its deletion.
//
// Author: Mark Mentovai
#ifndef PROCESSOR_MINIDUMP_H__
#define PROCESSOR_MINIDUMP_H__
// TODO(mmentovai): is it ok to include non-<string> header in .h?
#include <map>
#include <string>
#include <vector>
#include "processor/minidump_format.h"
#include "processor/memory_region.h"
#include "processor/range_map.h"
namespace google_airbag {
using std::map;
using std::string;
using std::vector;
class Minidump;
// MinidumpObject is the base of all Minidump* objects except for Minidump
// itself.
class MinidumpObject {
public:
virtual ~MinidumpObject() {}
protected:
MinidumpObject(Minidump* minidump);
// Refers to the Minidump object that is the ultimate parent of this
// Some MinidumpObjects are owned by other MinidumpObjects, but at the
// root of the ownership tree is always a Minidump. The Minidump object
// is kept here for access to its seeking and reading facilities, and
// for access to data about the minidump file itself, such as whether
// it should be byte-swapped.
Minidump* minidump_;
// MinidumpObjects are not valid when created. When a subclass populates
// its own fields, it can set valid_ to true. Accessors and mutators may
// wish to consider or alter the valid_ state as they interact with
// objects.
bool valid_;
};
// This class exists primarily to provide a virtual destructor in a base
// class common to all objects that might be stored in
// Minidump::mStreamObjects. Some object types (MinidumpContext) will
// never be stored in Minidump::mStreamObjects, but are represented as
// streams and adhere to the same interface, and may be derived from
// this class.
class MinidumpStream : public MinidumpObject {
public:
virtual ~MinidumpStream() {}
protected:
MinidumpStream(Minidump* minidump);
private:
// Populate (and validate) the MinidumpStream. minidump_ is expected
// to be positioned at the beginning of the stream, so that the next
// read from the minidump will be at the beginning of the stream.
// expected_size should be set to the stream's length as contained in
// the MDRawDirectory record or other identifying record. A class
// that implements MinidumpStream can compare expected_size to a
// known size as an integrity check.
virtual bool Read(u_int32_t expected_size) = 0;
};
// MinidumpContext carries a CPU-specific MDRawContext structure, which
// contains CPU context such as register states. Each thread has its
// own context, and the exception record, if present, also has its own
// context. Note that if the exception record is present, the context it
// refers to is probably what the user wants to use for the exception
// thread, instead of that thread's own context. The exception thread's
// context (as opposed to the exception record's context) will contain
// context for the exception handler (which performs minidump generation),
// and not the context that caused the exception (which is probably what the
// user wants).
class MinidumpContext : public MinidumpStream {
public:
const MDRawContextX86* context() const {
return valid_ ? &context_ : NULL; }
// Print a human-readable representation of the object to stdout.
void Print();
private:
friend class MinidumpThread;
friend class MinidumpException;
MinidumpContext(Minidump* minidump);
bool Read(u_int32_t expected_size);
// TODO(mmentovai): This is x86-only for now. When other CPUs are
// supported, this class can move to MinidumpContext_x86 and derive from
// a new abstract MinidumpContext.
MDRawContextX86 context_;
};
// MinidumpMemoryRegion does not wrap any MDRaw structure, and only contains
// a reference to an MDMemoryDescriptor. This object is intended to wrap
// portions of a minidump file that contain memory dumps. In normal
// minidumps, each MinidumpThread owns a MinidumpMemoryRegion corresponding
// to the thread's stack memory. MinidumpMemoryList also gives access to
// memory regions in its list as MinidumpMemoryRegions. This class
// adheres to MemoryRegion so that it may be used as a data provider to
// the Stackwalker family of classes.
class MinidumpMemoryRegion : public MinidumpObject,
public MemoryRegion {
public:
~MinidumpMemoryRegion();
// Returns a pointer to the base of the memory region. Returns the
// cached value if available, otherwise, reads the minidump file and
// caches the memory region.
const u_int8_t* GetMemory();
// The address of the base of the memory region.
u_int64_t GetBase();
// The size, in bytes, of the memory region.
u_int32_t GetSize();
// Frees the cached memory region, if cached.
void FreeMemory();
// Obtains the value of memory at the pointer specified by address.
bool GetMemoryAtAddress(u_int64_t address, u_int8_t* value);
bool GetMemoryAtAddress(u_int64_t address, u_int16_t* value);
bool GetMemoryAtAddress(u_int64_t address, u_int32_t* value);
bool GetMemoryAtAddress(u_int64_t address, u_int64_t* value);
// Print a human-readable representation of the object to stdout.
void Print();
private:
friend class MinidumpThread;
friend class MinidumpMemoryList;
MinidumpMemoryRegion(Minidump* minidump);
// Identify the base address and size of the memory region, and the
// location it may be found in the minidump file.
void SetDescriptor(MDMemoryDescriptor* descriptor);
// Implementation for GetMemoryAtAddress
template<typename T> bool GetMemoryAtAddressInternal(u_int64_t address,
T* value);
// Base address and size of the memory region, and its position in the
// minidump file.
MDMemoryDescriptor* descriptor_;
// Cached memory.
vector<u_int8_t>* memory_;
};
// MinidumpThread contains information about a thread of execution,
// including a snapshot of the thread's stack and CPU context. For
// the thread that caused an exception, the context carried by
// MinidumpException is probably desired instead of the CPU context
// provided here.
class MinidumpThread : public MinidumpObject {
public:
~MinidumpThread();
const MDRawThread* thread() const { return valid_ ? &thread_ : NULL; }
MinidumpMemoryRegion* GetMemory();
MinidumpContext* GetContext();
// The thread ID is used to determine if a thread is the exception thread,
// so a special getter is provided to retrieve this data from the
// MDRawThread structure.
u_int32_t GetThreadID();
// Print a human-readable representation of the object to stdout.
void Print();
private:
// This objects are managed by MinidumpThreadList.
friend class MinidumpThreadList;
MinidumpThread(Minidump* minidump);
// This works like MinidumpStream::Read, but is driven by
// MinidumpThreadList. No size checking is done, because
// MinidumpThreadList handles that directly.
bool Read();
MDRawThread thread_;
MinidumpMemoryRegion* memory_;
MinidumpContext* context_;
};
// MinidumpThreadList contains all of the threads (as MinidumpThreads) in
// a process.
class MinidumpThreadList : public MinidumpStream {
public:
~MinidumpThreadList();
unsigned int thread_count() const { return valid_ ? thread_count_ : 0; }
// Sequential access to threads.
MinidumpThread* GetThreadAtIndex(unsigned int index) const;
// Random access to threads.
MinidumpThread* GetThreadByID(u_int32_t thread_id);
// Print a human-readable representation of the object to stdout.
void Print();
private:
friend class Minidump;
typedef map<u_int32_t, MinidumpThread*> IDToThreadMap;
typedef vector<MinidumpThread> MinidumpThreads;
static const u_int32_t kStreamType = THREAD_LIST_STREAM;
MinidumpThreadList(Minidump* aMinidump);
bool Read(u_int32_t aExpectedSize);
// Access to threads using the thread ID as the key.
IDToThreadMap id_to_thread_map_;
// The list of threads.
MinidumpThreads* threads_;
u_int32_t thread_count_;
};
// MinidumpModule wraps MDRawModule, which contains information about loaded
// code modules. Access is provided to various data referenced indirectly
// by MDRawModule, such as the module's name and a specification for where
// to locate debugging information for the module.
class MinidumpModule : public MinidumpObject {
public:
~MinidumpModule();
const MDRawModule* module() const { return valid_ ? &module_ : 0; }
u_int64_t base_address() const {
return valid_ ? module_.base_of_image : static_cast<u_int64_t>(-1); }
u_int32_t size() const { return valid_ ? module_.size_of_image : 0; }
// The name of the file containing this module's code (exe, dll, so,
// dylib).
const string* GetName();
// The CodeView record, which contains information to locate the module's
// debugging information (pdb). This is returned as u_int8_t* because
// the data can be one of two types: MDCVInfoPDB20* or MDCVInfoPDB70*.
// Check the record's signature in the first four bytes to differentiate.
// Current toolchains generate modules which carry MDCVInfoPDB70.
const u_int8_t* GetCVRecord();
// The miscellaneous debug record, which is obsolete. Current toolchains
// do not generate this type of debugging information (dbg), and this
// field is not expected to be present.
const MDImageDebugMisc* GetMiscRecord();
// The filename of the file containing debugging information for this
// module. This data is supplied by the CodeView record, if present, or
// the miscellaneous debug record. As such, it will reference either a
// pdb or dbg file.
const string* GetDebugFilename();
// Print a human-readable representation of the object to stdout.
void Print();
private:
// These objects are managed by MinidumpModuleList.
friend class MinidumpModuleList;
MinidumpModule(Minidump* minidump);
// This works like MinidumpStream::Read, but is driven by
// MinidumpModuleList. No size checking is done, because
// MinidumpModuleList handles that directly.
bool Read();
MDRawModule module_;
// Cached module name.
const string* name_;
// Cached CodeView record - this is MDCVInfoPDB20 or (likely)
// MDCVInfoPDB70. Stored as a u_int8_t because the structure contains
// a variable-sized string and its exact size cannot be known until it
// is processed.
vector<u_int8_t>* cv_record_;
// Cached MDImageDebugMisc (usually not present), stored as u_int8_t
// because the structure contains a variable-sized string and its exact
// size cannot be known until it is processed.
vector<u_int8_t>* misc_record_;
// Cached debug filename.
const string* debug_filename_;
};
// MinidumpModuleList contains all of the loaded code modules for a process
// in the form of MinidumpModules. It maintains a map of these modules
// so that it may easily provide a code module corresponding to a specific
// address.
class MinidumpModuleList : public MinidumpStream {
public:
~MinidumpModuleList();
unsigned int module_count() const { return valid_ ? module_count_ : 0; }
// Sequential access to modules.
MinidumpModule* GetModuleAtIndex(unsigned int index) const;
// Random access to modules. Returns the module whose code is present
// at the address identified by address.
MinidumpModule* GetModuleForAddress(u_int64_t address);
// Print a human-readable representation of the object to stdout.
void Print();
private:
friend class Minidump;
typedef vector<MinidumpModule> MinidumpModules;
static const u_int32_t kStreamType = MODULE_LIST_STREAM;
MinidumpModuleList(Minidump* minidump);
bool Read(u_int32_t expected_size);
// Access to modules using addresses as the key.
RangeMap<u_int64_t, unsigned int> range_map_;
MinidumpModules* modules_;
u_int32_t module_count_;
};
// MinidumpMemoryList corresponds to a minidump's MEMORY_LIST_STREAM stream,
// which references the snapshots of all of the memory regions contained
// within the minidump. For a normal minidump, this includes stack memory
// (also referenced by each MinidumpThread, in fact, the MDMemoryDescriptors
// here and in MDRawThread both point to exactly the same data in a
// minidump file, conserving space), as well as a 256-byte snapshot of memory
// surrounding the instruction pointer in the case of an exception. Other
// types of minidumps may contain significantly more memory regions. Full-
// memory minidumps contain all of a process' mapped memory.
class MinidumpMemoryList : public MinidumpStream {
public:
~MinidumpMemoryList();
unsigned int region_count() const { return valid_ ? region_count_ : 0; }
// Sequential access to memory regions.
MinidumpMemoryRegion* GetMemoryRegionAtIndex(unsigned int index);
// Random access to memory regions. Returns the region encompassing
// the address identified by address.
MinidumpMemoryRegion* GetMemoryRegionForAddress(u_int64_t address);
// Print a human-readable representation of the object to stdout.
void Print();
private:
friend class Minidump;
typedef vector<MDMemoryDescriptor> MemoryDescriptors;
typedef vector<MinidumpMemoryRegion> MemoryRegions;
static const u_int32_t kStreamType = MEMORY_LIST_STREAM;
MinidumpMemoryList(Minidump* minidump);
bool Read(u_int32_t expected_size);
// Access to memory regions using addresses as the key.
RangeMap<u_int64_t, unsigned int> range_map_;
// The list of descriptors. This is maintained separately from the list
// of regions, because MemoryRegion doesn't own its MemoryDescriptor, it
// maintains a pointer to it. descriptors_ provides the storage for this
// purpose.
MemoryDescriptors* descriptors_;
// The list of regions.
MemoryRegions* regions_;
u_int32_t region_count_;
};
// MinidumpException wraps MDRawExceptionStream, which contains information
// about the exception that caused the minidump to be generated, if the
// minidump was generated in an exception handler called as a result of
// an exception. It also provides access to a MinidumpContext object,
// which contains the CPU context for the exception thread at the time
// the exception occurred.
class MinidumpException : public MinidumpStream {
public:
~MinidumpException();
const MDRawExceptionStream* exception() const {
return valid_ ? &exception_ : 0; }
// The thread ID is used to determine if a thread is the exception thread,
// so a special getter is provided to retrieve this data from the
// MDRawExceptionStream structure.
u_int32_t GetThreadID();
MinidumpContext* GetContext();
// Print a human-readable representation of the object to stdout.
void Print();
private:
friend class Minidump;
static const u_int32_t kStreamType = EXCEPTION_STREAM;
MinidumpException(Minidump* minidump);
bool Read(u_int32_t expected_size);
MDRawExceptionStream exception_;
MinidumpContext* context_;
};
// MinidumpSystemInfo wraps MDRawSystemInfo and provides information about
// the system on which the minidump was generated. See also MinidumpMiscInfo.
class MinidumpSystemInfo : public MinidumpStream {
public:
~MinidumpSystemInfo();
const MDRawSystemInfo* system_info() const {
return valid_ ? &system_info_ : 0; }
// I don't know what CSD stands for, but this field is documented as
// returning a textual representation of the OS service pack.
const string* GetCSDVersion();
// Print a human-readable representation of the object to stdout.
void Print();
private:
friend class Minidump;
static const u_int32_t kStreamType = SYSTEM_INFO_STREAM;
MinidumpSystemInfo(Minidump* minidump);
bool Read(u_int32_t expected_size);
MDRawSystemInfo system_info_;
// Textual representation of the OS service pack, for minidumps produced
// by MiniDumpWriteDump on Windows.
const string* csd_version_;
};
// MinidumpMiscInfo wraps MDRawMiscInfo and provides information about
// the process that generated the minidump, and optionally additional system
// information. See also MinidumpSystemInfo.
class MinidumpMiscInfo : public MinidumpStream {
public:
const MDRawMiscInfo* misc_info() const {
return valid_ ? &misc_info_ : 0; }
// Print a human-readable representation of the object to stdout.
void Print();
private:
friend class Minidump;
static const u_int32_t kStreamType = MISC_INFO_STREAM;
MinidumpMiscInfo(Minidump* minidump_);
bool Read(u_int32_t expected_size_);
MDRawMiscInfo misc_info_;
};
// Minidump is the user's interface to a minidump file. It wraps MDRawHeader
// and provides access to the minidump's top-level stream directory.
class Minidump {
public:
// fd is a randomly seekable file descriptor that is open and is
// positioned at the beginning of the MDRawHeader structure (byte offset
// 0).
Minidump(int fd);
~Minidump();
const MDRawHeader* header() const { return valid_ ? &header_ : 0; }
// Reads the minidump file's header and top-level stream directory.
// The minidump is expected to be positioned at the beginning of the
// header. Read() sets up the stream list and map, and validates the
// Minidump object.
bool Read();
// The next 6 methods are stubs that call GetStream. They exist to
// force code generation of the templatized API within the module, and
// to avoid exposing an ugly API (GetStream needs to accept a garbage
// parameter).
MinidumpThreadList* GetThreadList();
MinidumpModuleList* GetModuleList();
MinidumpMemoryList* GetMemoryList();
MinidumpException* GetException();
MinidumpSystemInfo* GetSystemInfo();
MinidumpMiscInfo* GetMiscInfo();
// The next set of methods are provided for users who wish to access
// data in minidump files directly, while leveraging the rest of
// this class and related classes to handle the basic minidump
// structure and known stream types.
unsigned int GetDirectoryEntryCount() const {
return valid_ ? header_.stream_count : 0; }
const MDRawDirectory* GetDirectoryEntryAtIndex(unsigned int index) const;
// The next 2 methods are lower-level I/O routines. They use fd_.
// Reads count bytes from the minidump at the current position into
// the storage area pointed to by bytes. bytes must be of sufficient
// size. After the read, the file position is advanced by count.
bool ReadBytes(void* bytes, size_t count);
// Sets the position of the minidump file to offset.
bool SeekSet(off_t offset);
// The next 2 methods are medium-level I/O routines.
// ReadString returns a string which is owned by the caller! offset
// specifies the offset that a length-encoded string is stored at in the
// minidump file.
string* ReadString(off_t offset);
// SeekToStreamType positions the file at the beginning of a stream
// identified by stream_type, and informs the caller of the stream's
// length by setting *stream_length. Because stream_map maps each stream
// type to only one stream in the file, this might mislead the user into
// thinking that the stream that this seeks to is the only stream with
// type stream_type. That can't happen for streams that these classes
// deal with directly, because they're only supposed to be present in the
// file singly, and that's verified when stream_map_ is built. Users who
// are looking for other stream types should be aware of this
// possibility, and consider using GetDirectoryEntryAtIndex (possibly
// with GetDirectoryEntryCount) if expecting multiple streams of the same
// type in a single minidump file.
bool SeekToStreamType(u_int32_t stream_type, u_int32_t* stream_length);
// Print a human-readable representation of the object to stdout.
void Print();
private:
// These classes are friends to give them access to this class' file
// I/O utility routines.
friend class MinidumpContext;
friend class MinidumpMemoryRegion;
friend class MinidumpThread;
friend class MinidumpThreadList;
friend class MinidumpModule;
friend class MinidumpModuleList;
friend class MinidumpMemoryList;
friend class MinidumpException;
friend class MinidumpSystemInfo;
friend class MinidumpMiscInfo;
// MinidumpStreamInfo is used in the MinidumpStreamMap. It lets
// the Minidump object locate interesting streams quickly, and
// provides a convenient place to stash MinidumpStream objects.
struct MinidumpStreamInfo {
MinidumpStreamInfo()
: stream_index(0)
, stream(NULL) {}
~MinidumpStreamInfo() { delete stream; }
// Index into the MinidumpDirectoryEntries vector
unsigned int stream_index;
// Pointer to the stream if cached, or NULL if not yet populated
MinidumpStream* stream;
};
typedef vector<MDRawDirectory> MinidumpDirectoryEntries;
typedef map<u_int32_t, MinidumpStreamInfo> MinidumpStreamMap;
bool swap() const { return valid_ ? swap_ : false; }
template<typename T> T* GetStream(T** stream);
MDRawHeader header_;
// The list of streams.
MinidumpDirectoryEntries* directory_;
// Access to streams using the stream type as the key.
MinidumpStreamMap* stream_map_;
// The file descriptor for all file I/O. Used by ReadBytes and SeekSet.
int fd_;
// swap_ is true if the minidump file should be byte-swapped. If the
// minidump was produced by a CPU that is other-endian than the CPU
// processing the minidump, this will be true. If the two CPUs are
// same-endian, this will be false.
bool swap_;
// Validity of the Minidump structure, false immediately after
// construction or after a failed Read(); true following a successful
// Read().
bool valid_;
};
} // namespace google_airbag
#endif // PROCESSOR_MINIDUMP_H__

View file

@ -0,0 +1,110 @@
// Copyright (C) 2006 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// minidump_dump.cc: Print the contents of a minidump file in somewhat
// readable text.
//
// Author: Mark Mentovai
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifndef _WIN32
#include <unistd.h>
#define O_BINARY 0
#else // !_WIN32
#include <io.h>
#define open _open
#endif // !_WIN32
#include "processor/minidump.h"
using namespace google_airbag;
int main(int argc, char** argv) {
if (argc != 2) {
fprintf(stderr, "usage: %s <file>\n", argv[0]);
exit(1);
}
int fd = open(argv[1], O_RDONLY | O_BINARY);
if (fd == -1) {
printf("open failed\n");
exit(1);
}
Minidump minidump(fd);
if (!minidump.Read()) {
printf("minidump.Read() failed\n");
exit(1);
}
minidump.Print();
int error = 0;
MinidumpThreadList* threadList = minidump.GetThreadList();
if (!threadList) {
error |= 1 << 2;
printf("minidump.GetThreadList() failed\n");
} else {
threadList->Print();
}
MinidumpModuleList* moduleList = minidump.GetModuleList();
if (!moduleList) {
error |= 1 << 3;
printf("minidump.GetModuleList() failed\n");
} else {
moduleList->Print();
}
MinidumpMemoryList* memoryList = minidump.GetMemoryList();
if (!memoryList) {
error |= 1 << 4;
printf("minidump.GetMemoryList() failed\n");
} else {
memoryList->Print();
}
MinidumpException* exception = minidump.GetException();
if (!exception) {
error |= 1 << 5;
printf("minidump.GetException() failed\n");
} else {
exception->Print();
}
MinidumpSystemInfo* systemInfo = minidump.GetSystemInfo();
if (!systemInfo) {
error |= 1 << 6;
printf("minidump.GetSystemInfo() failed\n");
} else {
systemInfo->Print();
}
MinidumpMiscInfo* miscInfo = minidump.GetMiscInfo();
if (!miscInfo) {
error |= 1 << 7;
printf("minidump.GetMiscInfo() failed\n");
} else {
miscInfo->Print();
}
// Use return instead of exit to allow destructors to run.
return(error);
}

View file

@ -0,0 +1,6 @@
#!/bin/sh
testdata_dir=$srcdir/src/processor/testdata
./src/processor/minidump_dump $testdata_dir/minidump1.dmp | \
tr -s '\015' '\012' | \
diff -u $testdata_dir/minidump1.out -
exit $?

View file

@ -0,0 +1,555 @@
/* Copyright (C) 2006 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License. */
/* minidump_format.h: A cross-platform reimplementation of minidump-related
* portions of DbgHelp.h from the Windows Platform SDK.
*
* (This is C99 source, please don't corrupt it with C++.)
*
* This file contains the necessary definitions to read minidump files
* produced on win32/x86. These files may be read on any platform provided
* that the alignments of these structures on the processing system are
* identical to the alignments of these structures on the producing system.
* For this reason, precise-sized types are used. The structures defined by
* by this file have been laid out to minimize alignment problems by ensuring
* ensuring that all members are aligned on their natural boundaries. In
* In some cases, tail-padding may be significant when different ABIs specify
* different tail-padding behaviors. To avoid problems when reading or
* writing affected structures, MD_*_SIZE macros are provided where needed,
* containing the useful size of the structures without padding.
*
* These structures are also sufficient to populate minidump files.
*
* These definitions may be extended to support handling minidump files
* for other CPUs and other operating systems.
*
* Because precise data type sizes are crucial for this implementation to
* function properly and portably in terms of interoperability with minidumps
* produced by DbgHelp on Windows, a set of primitive types with known sizes
* are used as the basis of each structure defined by this file. DbgHelp
* on Windows is assumed to be the reference implementation; this file
* seeks to provide a cross-platform compatible implementation. To avoid
* collisions with the types and values defined and used by DbgHelp in the
* event that this implementation is used on Windows, each type and value
* defined here is given a new name, beginning with "MD". Names of the
* equivlaent types and values in the Windows Platform SDK are given in
* comments.
*
* Author: Mark Mentovai */
#ifndef PROCESSOR_MINIDUMP_FORMAT_H__
#define PROCESSOR_MINIDUMP_FORMAT_H__
#include "google/airbag_types.h"
/*
* guiddef.h
*/
typedef struct {
u_int32_t data1;
u_int16_t data2;
u_int16_t data3;
u_int8_t data4[8];
} MDGUID; /* GUID */
/*
* WinNT.h
*/
#define MD_FLOATINGSAVEAREA_SIZEOF_REGISTERAREA_X86 80
/* SIZE_OF_80387_REGISTERS */
typedef struct {
u_int32_t control_word;
u_int32_t status_word;
u_int32_t tag_word;
u_int32_t error_offset;
u_int32_t error_selector;
u_int32_t data_offset;
u_int32_t data_selector;
u_int8_t register_area[MD_FLOATINGSAVEAREA_SIZEOF_REGISTERAREA_X86];
u_int32_t cr0_npx_state;
} MDFloatingSaveAreaX86; /* FLOATING_SAVE_AREA */
#define MD_CONTEXT_SIZEOF_EXTENDED_REGISTERS_X86 512
/* MAXIMUM_SUPPORTED_EXTENSION */
typedef struct {
/* The next field determines the layout of the structure, and what parts
* of it are populated */
u_int32_t context_flags;
/* The next 6 registers are included with MD_CONTEXT_X86_DEBUG_REGISTERS */
u_int32_t dr0;
u_int32_t dr1;
u_int32_t dr2;
u_int32_t dr3;
u_int32_t dr6;
u_int32_t dr7;
/* The next field is included with MD_CONTEXT_X86_FLOATING_POINT */
MDFloatingSaveAreaX86 float_save;
/* The next 4 registers are included with MD_CONTEXT_X86_SEGMENTS */
u_int32_t gs;
u_int32_t fs;
u_int32_t es;
u_int32_t ds;
/* The next 6 registers are included with MD_CONTEXT_X86_INTEGER */
u_int32_t edi;
u_int32_t esi;
u_int32_t ebx;
u_int32_t edx;
u_int32_t ecx;
u_int32_t eax;
/* The next 6 registers are included with MD_CONTEXT_X86_CONTROL */
u_int32_t ebp;
u_int32_t eip;
u_int32_t cs; /* WinNT.h says "must be sanitized" */
u_int32_t eflags; /* WinNT.h says "must be sanitized" */
u_int32_t esp;
u_int32_t ss;
/* The next field is included with MD_CONTEXT_X86_EXTENDED_REGISTERS */
u_int8_t extended_registers[
MD_CONTEXT_SIZEOF_EXTENDED_REGISTERS_X86];
} MDRawContextX86; /* CONTEXT */
/* For (MDRawContextX86).context_flags. These values indicate the type of
* context stored in the structure. */
#define MD_CONTEXT_X86_X86 0x00010000
/* CONTEXT_i386, CONTEXT_i486: identifies CPU */
#define MD_CONTEXT_X86_CONTROL (MD_CONTEXT_X86_X86 | 0x00000001)
/* CONTEXT_CONTROL */
#define MD_CONTEXT_X86_INTEGER (MD_CONTEXT_X86_X86 | 0x00000002)
/* CONTEXT_INTEGER */
#define MD_CONTEXT_X86_SEGMENTS (MD_CONTEXT_X86_X86 | 0x00000004)
/* CONTEXT_SEGMENTS */
#define MD_CONTEXT_X86_FLOATING_POINT (MD_CONTEXT_X86_X86 | 0x00000008)
/* CONTEXT_FLOATING_POINT */
#define MD_CONTEXT_X86_DEBUG_REGISTERS (MD_CONTEXT_X86_X86 | 0x00000010)
/* CONTEXT_DEBUG_REGISTERS */
#define MD_CONTEXT_X86_EXTENED_REGISTERS (MD_CONTEXT_X86_X86 | 0x00000020)
/* CONTEXT_EXTENDED_REGISTERS */
#define MD_CONTEXT_X86_FULL (MD_CONTEXT_X86_CONTROL | \
MD_CONTEXT_X86_INTEGER | \
MD_CONTEXT_X86_SEGMENTS)
/* CONTEXT_FULL */
#define MD_CONTEXT_X86_ALL (MD_CONTEXT_X86_FULL | \
MD_CONTEXT_X86_FLOATING_POINT | \
MD_CONTEXT_X86_DEBUG_REGISTERS | \
MD_CONTEXT_X86_EXTENDED_REGISTERS)
/* CONTEXT_ALL */
/*
* WinVer.h
*/
typedef struct {
u_int32_t signature;
u_int32_t struct_version;
u_int32_t file_version_hi;
u_int32_t file_version_lo;
u_int32_t product_version_hi;
u_int32_t product_version_lo;
u_int32_t file_flags_mask; /* Identifies valid bits in fileFlags */
u_int32_t file_flags;
u_int32_t file_os;
u_int32_t file_type;
u_int32_t file_subtype;
u_int32_t file_date_hi;
u_int32_t file_date_lo;
} MDVSFixedFileInfo; /* VS_FIXEDFILEINFO */
/* For (MDVSFixedFileInfo).signature */
#define MD_VSFIXEDFILEINFO_SIGNATURE 0xfeef04bd
/* VS_FFI_SIGNATURE */
/* For (MDVSFixedFileInfo).version */
#define MD_VSFIXEDFILEINFO_VERSION 0x00010000
/* VS_FFI_STRUCVERSION */
/* For (MDVSFixedFileInfo).file_flags_mask and
* (MDVSFixedFileInfo).file_flags */
#define MD_VSFIXEDFILEINFO_FILE_FLAGS_DEBUG 0x00000001
/* VS_FF_DEBUG */
#define MD_VSFIXEDFILEINFO_FILE_FLAGS_PRERELEASE 0x00000002
/* VS_FF_PRERELEASE */
#define MD_VSFIXEDFILEINFO_FILE_FLAGS_PATCHED 0x00000004
/* VS_FF_PATCHED */
#define MD_VSFIXEDFILEINFO_FILE_FLAGS_PRIVATEBUILD 0x00000008
/* VS_FF_PRIVATEBUILD */
#define MD_VSFIXEDFILEINFO_FILE_FLAGS_INFOINFERRED 0x00000010
/* VS_FF_INFOINFERRED */
#define MD_VSFIXEDFILEINFO_FILE_FLAGS_SPECIALBUILD 0x00000020
/* VS_FF_SPECIALBUILD */
/* For (MDVSFixedFileInfo).file_os: high 16 bits */
#define MD_VSFIXEDFILEINFO_FILE_OS_UNKNOWN 0 /* VOS_UNKNOWN */
#define MD_VSFIXEDFILEINFO_FILE_OS_DOS (1 << 16) /* VOS_DOS */
#define MD_VSFIXEDFILEINFO_FILE_OS_OS216 (2 << 16) /* VOS_OS216 */
#define MD_VSFIXEDFILEINFO_FILE_OS_OS232 (3 << 16) /* VOS_OS232 */
#define MD_VSFIXEDFILEINFO_FILE_OS_NT (4 << 16) /* VOS_NT */
#define MD_VSFIXEDFILEINFO_FILE_OS_WINCE (5 << 16) /* VOS_WINCE */
/* Low 16 bits */
#define MD_VSFIXEDFILEINFO_FILE_OS__BASE 0 /* VOS__BASE */
#define MD_VSFIXEDFILEINFO_FILE_OS__WINDOWS16 1 /* VOS__WINDOWS16 */
#define MD_VSFIXEDFILEINFO_FILE_OS__PM16 2 /* VOS__PM16 */
#define MD_VSFIXEDFILEINFO_FILE_OS__PM32 3 /* VOS__PM32 */
#define MD_VSFIXEDFILEINFO_FILE_OS__WINDOWS32 4 /* VOS__WINDOWS32 */
/* For (MDVSFixedFileInfo).file_type */
#define MD_VSFIXEDFILEINFO_FILE_TYPE_UNKNOWN 0 /* VFT_UNKNOWN */
#define MD_VSFIXEDFILEINFO_FILE_TYPE_APP 1 /* VFT_APP */
#define MD_VSFIXEDFILEINFO_FILE_TYPE_DLL 2 /* VFT_DLL */
#define MD_VSFIXEDFILEINFO_FILE_TYPE_DRV 3 /* VFT_DLL */
#define MD_VSFIXEDFILEINFO_FILE_TYPE_FONT 4 /* VFT_FONT */
#define MD_VSFIXEDFILEINFO_FILE_TYPE_VXD 5 /* VFT_VXD */
#define MD_VSFIXEDFILEINFO_FILE_TYPE_STATIC_LIB 7 /* VFT_STATIC_LIB */
/* For (MDVSFixedFileInfo).file_subtype */
#define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_UNKNOWN 0
/* VFT2_UNKNOWN */
/* with file_type = MD_VSFIXEDFILEINFO_FILETYPE_DRV */
#define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_PRINTER 1
/* VFT2_DRV_PRINTER */
#define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_KEYBOARD 2
/* VFT2_DRV_KEYBOARD */
#define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_LANGUAGE 3
/* VFT2_DRV_LANGUAGE */
#define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_DISPLAY 4
/* VFT2_DRV_DISPLAY */
#define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_MOUSE 5
/* VFT2_DRV_MOUSE */
#define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_NETWORK 6
/* VFT2_DRV_NETWORK */
#define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_SYSTEM 7
/* VFT2_DRV_SYSTEM */
#define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_INSTALLABLE 8
/* VFT2_DRV_INSTALLABLE */
#define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_SOUND 9
/* VFT2_DRV_SOUND */
#define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_COMM 10
/* VFT2_DRV_COMM */
#define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_INPUTMETHOD 11
/* VFT2_DRV_INPUTMETHOD */
#define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_VERSIONED_PRINTER 12
/* VFT2_DRV_VERSIONED_PRINTER */
/* with file_type = MD_VSFIXEDFILEINFO_FILETYPE_FONT */
#define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_FONT_RASTER 1
/* VFT2_FONT_RASTER */
#define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_FONT_VECTOR 2
/* VFT2_FONT_VECTOR */
#define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_FONT_TRUETYPE 3
/* VFT2_FONT_TRUETYPE */
/*
* DbgHelp.h
*/
typedef u_int32_t MDRVA; /* RVA */
typedef struct {
u_int32_t data_size;
MDRVA rva;
} MDLocationDescriptor; /* MINIDUMP_LOCATION_DESCRIPTOR */
typedef struct {
u_int64_t start_of_memory_range;
MDLocationDescriptor memory;
} MDMemoryDescriptor; /* MINIDUMP_MEMORY_DESCRIPTOR */
typedef struct {
u_int32_t signature;
u_int32_t version;
u_int32_t stream_count;
MDRVA stream_directory_rva;
u_int32_t checksum;
u_int32_t time_date_stamp; /* time_t */
u_int64_t flags;
} MDRawHeader; /* MINIDUMP_HEADER */
/* For (MDRawHeader).signature and (MDRawHeader).version. Note that only the
* low 16 bits of (MDRawHeader).version are MD_HEADER_VERSION. Per the
* documentation, the high 16 bits are implementation-specific. */
#define MD_HEADER_SIGNATURE 0x504d444d /* 'PMDM' */
/* MINIDUMP_SIGNATURE */
#define MD_HEADER_VERSION 0x0000a793 /* 42899 */
/* MINIDUMP_VERSION */
/* For (MDRawHeader).flags */
typedef enum {
MINIDUMP_NORMAL = 0x00000000,
MINIDUMP_WITH_DATA_SEGS = 0x00000001,
MINIDUMP_WITH_FULL_MEMORY = 0x00000002,
MINIDUMP_WITH_HANDLE_DATA = 0x00000004,
MINIDUMP_FILTER_MEMORY = 0x00000008,
MINIDUMP_SCAN_MEMORY = 0x00000010,
MINIDUMP_WITH_UNLOADED_MODULES = 0x00000020,
MINIDUMP_WITH_INDIRECTLY_REFERENCED_MEMORY = 0X00000040,
MINIDUMP_FILTER_MODULE_PATHS = 0x00000080,
MINIDUMP_WITH_PROCESS_THREAD_DATA = 0x00000100,
MINIDUMP_WITH_PRIVATE_READ_WRITE_MEMORY = 0x00000200,
MINIDUMP_WITHOUT_OPTIONAL_DATA = 0x00000400,
MINIDUMP_WITH_FULL_MEMORY_INFO = 0x00000800,
MINIDUMP_WITH_THREAD_INFO = 0x00001000,
MINIDUMP_WITH_CODE_SEGS = 0x00002000
} MDType; /* MINIDUMP_TYPE */
typedef struct {
u_int32_t stream_type;
MDLocationDescriptor location;
} MDRawDirectory; /* MINIDUMP_DIRECTORY */
/* For (MDRawDirectory).stream_type */
typedef enum {
UNUSED_STREAM = 0,
RESERVED_STREAM_0 = 1,
RESERVED_STREAM_1 = 2,
THREAD_LIST_STREAM = 3,
MODULE_LIST_STREAM = 4,
MEMORY_LIST_STREAM = 5,
EXCEPTION_STREAM = 6,
SYSTEM_INFO_STREAM = 7,
THREAD_EX_LIST_STREAM = 8,
MEMORY_64_LIST_STREAM = 9,
COMMENT_STREAM_A = 10,
COMMENT_STREAM_W = 11,
HANDLE_DATA_STREAM = 12,
FUNCTION_TABLE_STREAM = 13,
UNLOADED_MODULE_LIST_STREAM = 14,
MISC_INFO_STREAM = 15,
LAST_RESERVED_STREAM = 0x0000FFFF
} MDStreamType; /* MINIDUMP_STREAM_TYPE */
typedef struct {
u_int32_t thread_id;
u_int32_t suspend_count;
u_int32_t priority_class;
u_int32_t priority;
u_int64_t teb; /* Thread environment block */
MDMemoryDescriptor stack;
MDLocationDescriptor thread_context;
} MDRawThread; /* MINIDUMP_THREAD */
typedef struct {
u_int32_t number_of_threads;
MDRawThread threads[0];
} MDRawThreadList; /* MINIDUMP_THREAD_LIST */
typedef struct {
u_int64_t base_of_image;
u_int32_t size_of_image;
u_int32_t checksum;
u_int32_t time_date_stamp;
MDRVA module_name_rva;
MDVSFixedFileInfo version_info;
/* The next field stores a CodeView record and is populated when a module's
* debug information resides in a PDB file. It identifies the PDB file. */
MDLocationDescriptor cv_record;
/* The next field is populated when a module's debug information resides
* in a DBG file. It identifies the DBG file. This field is effectively
* obsolete with modules built by recent toolchains. */
MDLocationDescriptor misc_record;
/* Alignment problem: reserved0 and reserved1 are defined by the platform
* SDK as 64-bit quantities. However, that results in a structure whose
* alignment is unpredictable on different CPUs and ABIs. If the ABI
* specifies full alignment of 64-bit quantities in structures (as ppc
* does), there will be padding between miscRecord and reserved0. If
* 64-bit quantities can be aligned on 32-bit boundaries (as on x86),
* this padding will not exist. (Note that the structure up to this point
* contains 1 64-bit member followed by 21 32-bit members.)
* As a workaround, reserved0 and reserved1 are instead defined here as
* four 32-bit quantities. This should be harmless, as there are
* currently no known uses for these fields. */
u_int32_t reserved0[2];
u_int32_t reserved1[2];
} MDRawModule; /* MINIDUMP_MODULE */
/* The inclusion of a 64-bit type in MINIDUMP_MODULE forces the struct to
* be tail-padded out to a multiple of 64 bits under some ABIs (such as PPC).
* This doesn't occur on systems that don't tail-pad in this manner. Define
* this macro to be the usable size of the MDRawModule struct, and use it in
* place of sizeof(MDRawModule). */
#define MD_MODULE_SIZE 108
/* (MDRawModule).cv_record can reference MDCVInfoPDB20 or MDCVInfoPDB70.
* Ref.: http://www.debuginfo.com/articles/debuginfomatch.html
* MDCVInfoPDB70 is the expected structure type with recent toolchains. */
typedef struct {
u_int32_t signature;
u_int32_t offset; /* Offset to debug data (expect 0 in minidump) */
} MDCVHeader;
typedef struct {
MDCVHeader cv_header;
u_int32_t signature; /* time_t debug information created */
u_int32_t age; /* revision of PDB file */
u_int8_t pdb_file_name[0];
} MDCVInfoPDB20;
#define MD_CVINFOPDB20_SIGNATURE 0x3031424e /* cvHeader.signature = '01BN' */
typedef struct {
u_int32_t cv_signature;
MDGUID signature; /* GUID, identifies PDB file */
u_int32_t age; /* Identifies incremental changes to PDB file */
u_int8_t pdb_file_name[0]; /* 0-terminated 8-bit character data (UTF-8?) */
} MDCVInfoPDB70;
#define MD_CVINFOPDB70_SIGNATURE 0x53445352 /* cvSignature = 'SDSR' */
/* (MDRawModule).miscRecord can reference MDImageDebugMisc. The Windows
* structure is actually defined in WinNT.h. This structure is effectively
* obsolete with modules built by recent toolchains. */
typedef struct {
u_int32_t data_type;
u_int32_t length;
u_int8_t unicode;
u_int8_t reserved[3];
u_int8_t data[0];
} MDImageDebugMisc; /* IMAGE_DEBUG_MISC */
typedef struct {
u_int32_t number_of_modules;
MDRawModule modules[0];
} MDRawModuleList; /* MINIDUMP_MODULE_LIST */
typedef struct {
u_int32_t number_of_memory_ranges;
MDMemoryDescriptor memory_ranges[0];
} MDRawMemoryList; /* MINIDUMP_MEMORY_LIST */
#define MD_EXCEPTION_MAXIMUM_PARAMETERS 15
typedef struct {
u_int32_t exception_code;
u_int32_t exception_flags;
u_int64_t exception_record;
u_int64_t exception_address;
u_int32_t number_parameters;
u_int32_t __align;
u_int64_t exception_information[MD_EXCEPTION_MAXIMUM_PARAMETERS];
} MDException; /* MINIDUMP_EXCEPTION */
typedef struct {
u_int32_t thread_id;
u_int32_t __align;
MDException exception_record;
MDLocationDescriptor thread_context;
} MDRawExceptionStream; /* MINIDUMP_EXCEPTION_STREAM */
typedef union {
struct {
u_int32_t vendor_id[3]; /* cpuid 0: eax, ebx, ecx */
u_int32_t version_information; /* cpuid 1: eax */
u_int32_t feature_information; /* cpuid 1: edx */
u_int32_t amd_extended_cpu_features; /* cpuid 0x80000001, ebx */
} x86_cpu_info;
struct {
u_int64_t processor_features[2];
} other_cpu_info;
} MDCPUInformation; /* CPU_INFORMATION */
typedef struct {
/* The next 3 fields and numberOfProcessors are from the SYSTEM_INFO
* structure as returned by GetSystemInfo */
u_int16_t processor_architecture;
u_int16_t processor_level;
u_int16_t processor_revision;
union {
u_int16_t reserved0;
struct {
u_int8_t number_of_processors;
u_int8_t product_type;
};
};
/* The next 5 fields are from the OSVERSIONINFO structure as returned
* by GetVersionEx */
u_int32_t major_version;
u_int32_t minor_version;
u_int32_t build_number;
u_int32_t platform_id;
MDRVA csd_version_rva; /* Name of the installed OS service pack */
union {
u_int32_t reserved1;
struct {
u_int16_t suite_mask;
u_int16_t reserved2;
};
};
MDCPUInformation cpu;
} MDRawSystemInfo; /* MINIDUMP_SYSTEM_INFO */
typedef struct {
u_int32_t size_of_info;
u_int32_t flags1;
u_int32_t process_id;
u_int32_t process_create_time;
u_int32_t process_user_time;
u_int32_t process_kernel_time;
/* The following fields are not present in MINIDUMP_MISC_INFO but are
* in MINIDUMP_MISC_INFO_2. When this struct is populated, these values
* may not be set. Use flags1 or sizeOfInfo to determine whether these
* values are present. */
u_int32_t processor_max_mhz;
u_int32_t processor_current_mhz;
u_int32_t processor_mhz_limit;
u_int32_t processor_max_idle_state;
u_int32_t processor_current_idle_state;
} MDRawMiscInfo; /* MINIDUMP_MISC_INFO, MINIDUMP_MISC_INFO2 */
#define MD_MISCINFO_SIZE 24
#define MD_MISCINFO2_SIZE 44
#endif /* PROCESSOR_MINIDUMP_FORMAT_H__ */

158
src/processor/range_map.h Normal file
View file

@ -0,0 +1,158 @@
// Copyright (C) 2006 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// range_map.h: Range maps.
//
// A range map associates a range of addresses with a specific object. This
// is useful when certain objects of variable size are located within an
// address space. The range map makes it simple to determine which object is
// associated with a specific address, which may be any address within the
// range associated with an object.
//
// Author: Mark Mentovai
#ifndef PROCESSOR_RANGE_MAP_H__
#define PROCESSOR_RANGE_MAP_H__
#include <map>
namespace google_airbag {
using std::map;
template<typename AddressType, typename EntryType>
class RangeMap {
public:
RangeMap() : map_() {}
// Inserts a range into the map. Returns false for a parameter error,
// or if the location of the range would conflict with a range already
// stored in the map.
bool StoreRange(const AddressType& base,
const AddressType& size,
const EntryType& entry);
// Locates the range encompassing the supplied address. If there is
// no such range, or if there is a parameter error, returns false.
bool RetrieveRange(const AddressType& address, EntryType* entry);
// Empties the range map, restoring it to the state it was when it was
// initially created.
void Clear();
private:
class Range {
public:
Range(const AddressType& base, const EntryType& entry)
: base_(base), entry_(entry) {}
AddressType base() const { return base_; }
EntryType entry() const { return entry_; }
private:
// The base address of the range. The high address does not need to
// be stored, because RangeMap uses it as the key to the map.
const AddressType base_;
// The entry, owned by the Range object.
const EntryType entry_;
};
typedef map<AddressType, Range> AddressToRangeMap;
// Can't depend on implicit typenames in a template
typedef typename AddressToRangeMap::const_iterator const_iterator;
typedef typename AddressToRangeMap::value_type value_type;
// Maps the high address of each range to a EntryType.
AddressToRangeMap map_;
};
template<typename AddressType, typename EntryType>
bool RangeMap<AddressType, EntryType>::StoreRange(const AddressType& base,
const AddressType& size,
const EntryType& entry) {
AddressType high = base + size - 1;
// Check for undersize or overflow.
if (size <= 0 || high < base)
return false;
// Ensure that this range does not overlap with another one already in the
// map.
const_iterator iterator_base = map_.lower_bound(base);
const_iterator iterator_high = map_.lower_bound(high);
if (iterator_base != iterator_high) {
// Some other range begins in the space used by this range. It may be
// contained within the space used by this range, or it may extend lower.
// Regardless, it is an error.
return false;
}
if (iterator_high != map_.end()) {
if (iterator_high->second.base() <= high) {
// The range above this one overlaps with this one. It may fully
// contain this range, or it may begin within this range and extend
// higher. Regardless, it's an error.
return false;
}
}
// Store the range in the map by its high address, so that lower_bound can
// be used to quickly locate a range by address.
map_.insert(value_type(high, Range(base, entry)));
return true;
}
template<typename AddressType, typename EntryType>
bool RangeMap<AddressType, EntryType>::RetrieveRange(
const AddressType& address,
EntryType* entry) {
if (!entry)
return false;
const_iterator iterator = map_.lower_bound(address);
if (iterator == map_.end())
return false;
// The map is keyed by the high address of each range, so |address| is
// guaranteed to be lower than the range's high address. If |range| is
// not directly preceded by another range, it's possible for address to
// be below the range's low address, though. When that happens, address
// references something not within any range, so return false.
if (address < iterator->second.base())
return false;
*entry = iterator->second.entry();
return true;
}
template<typename AddressType, typename EntryType>
void RangeMap<AddressType, EntryType>::Clear() {
map_.clear();
}
} // namespace google_airbag
#endif // PROCESSOR_RANGE_MAP_H__

View file

@ -0,0 +1,334 @@
// Copyright (C) 2006 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// range_map_unittest.cc: Unit tests for RangeMap
//
// Author: Mark Mentovai
#include <stdio.h>
#include <climits>
#include <memory>
#include "processor/range_map.h"
using std::auto_ptr;
using google_airbag::RangeMap;
// A CountedObject holds an int. A global (not thread safe!) count of
// allocated CountedObjects is maintained to help test memory management.
class CountedObject {
public:
CountedObject(int id) : id_(id) { ++count_; }
CountedObject(const CountedObject& that) : id_(that.id_) { ++count_; }
~CountedObject() { --count_; }
static int count() { return count_; }
int id() const { return id_; }
private:
static int count_;
int id_;
};
int CountedObject::count_;
typedef int AddressType;
typedef RangeMap<AddressType, CountedObject> TestMap;
// RangeTest contains data to use for store and retrieve tests. See
// RunTests for descriptions of the tests.
struct RangeTest {
// Base address to use for test
AddressType address;
// Size of range to use for test
AddressType size;
// Unique ID of range - unstorable ranges must have unique IDs too
int id;
// Whether this range is expected to be stored successfully or not
bool expect_storable;
};
// A RangeTestSet encompasses multiple RangeTests, which are run in
// sequence on the same RangeMap.
struct RangeTestSet {
// An array of RangeTests
const RangeTest* range_tests;
// The number of tests in the set
unsigned int range_test_count;
};
// StoreTest uses the data in a RangeTest and calls StoreRange on the
// test RangeMap. It returns true if the expected result occurred, and
// false if something else happened.
bool StoreTest(TestMap* range_map, const RangeTest* range_test) {
CountedObject object(range_test->id);
bool stored = range_map->StoreRange(range_test->address,
range_test->size,
object);
if (stored != range_test->expect_storable) {
fprintf(stderr, "FAILED: "
"StoreRange id %d, expected %s, observed %s\n",
range_test->id,
range_test->expect_storable ? "storable" : "not storable",
stored ? "stored" : "not stored");
return false;
}
return true;
}
// RetrieveTest uses the data in RangeTest and calls RetrieveRange on the
// test RangeMap. If it retrieves the expected value (which can be no
// map entry at the specified range,) it returns true, otherwise, it returns
// false. RetrieveTest will check the values around the base address and
// the high address of a range to guard against off-by-one errors.
bool RetrieveTest(TestMap* range_map, const RangeTest* range_test) {
for (unsigned int side = 0; side <= 1; ++side) {
// When side == 0, check the low side (base address) of each range.
// When side == 1, check the high side (base + size) of each range.
// Check one-less and one-greater than the target address in addition
// to the target address itself.
// If the size of the range is only 1, don't check one greater than
// the base or one less than the high - for a successfully stored
// range, these tests would erroneously fail because the range is too
// small.
AddressType low_offset = -1;
AddressType high_offset = 1;
if (range_test->size == 1) {
if (!side) // when checking the low side,
high_offset = 0; // don't check one over the target
else // when checking the high side,
low_offset = 0; // don't check one under the target
}
for (AddressType offset = low_offset; offset <= high_offset; ++offset) {
AddressType address =
offset +
(!side ? range_test->address :
range_test->address + range_test->size - 1);
bool expected_result = false; // correct for tests not stored
if (range_test->expect_storable) {
if (offset == 0) // when checking target,
expected_result = true; // should always succeed
else if (offset == -1) // when checking one below target,
expected_result = side; // should fail low and succeed high
else // when checking one above target,
expected_result = !side; // should succeed low and fail high
}
CountedObject object(-1);
bool retrieved = range_map->RetrieveRange(address, &object);
bool observed_result = retrieved && object.id() == range_test->id;
if (observed_result != expected_result) {
fprintf(stderr, "FAILED: "
"RetrieveRange id %d, side %d, offset %d, "
"expected %s, observed %s\n",
range_test->id,
side,
offset,
expected_result ? "true" : "false",
observed_result ? "true" : "false");
return false;
}
}
}
return true;
}
// RunTests runs a series of test sets.
bool RunTests() {
// These tests will be run sequentially. The first set of tests exercises
// most functions of RangeTest, and verifies all of the bounds-checking.
const RangeTest range_tests_0[] = {
{ INT_MIN, 16, 1, true }, // lowest possible range
{ -2, 5, 2, true }, // a range through zero
{ INT_MAX - 9, 11, 3, false }, // tests anti-overflow
{ INT_MAX - 9, 10, 4, true }, // highest possible range
{ 5, 0, 5, false }, // tests anti-zero-size
{ 5, 1, 6, true }, // smallest possible range
{ -20, 15, 7, true }, // entirely negative
{ 10, 10, 10, true }, // causes the following tests to fail
{ 9, 10, 11, false }, // one-less base, one-less high
{ 9, 11, 12, false }, // one-less base, identical high
{ 9, 12, 13, false }, // completely contains existing
{ 10, 9, 14, false }, // identical base, one-less high
{ 10, 10, 15, false }, // exactly identical to existing range
{ 10, 11, 16, false }, // identical base, one-greater high
{ 11, 8, 17, false }, // contained completely within
{ 11, 9, 18, false }, // one-greater base, identical high
{ 11, 10, 19, false }, // one-greater base, one-greater high
{ 9, 2, 20, false }, // overlaps bottom by one
{ 10, 1, 21, false }, // overlaps bottom by one, contained
{ 19, 1, 22, false }, // overlaps top by one, contained
{ 19, 2, 23, false }, // overlaps top by one
{ 9, 1, 24, true }, // directly below without overlap
{ 20, 1, 25, true }, // directly above without overlap
{ 6, 3, 26, true }, // exactly between two ranges, gapless
{ 7, 3, 27, false }, // tries to span two ranges
{ 7, 5, 28, false }, // tries to span three ranges
{ 4, 20, 29, false }, // tries to contain several ranges
{ 30, 50, 30, true },
{ 90, 25, 31, true },
{ 35, 65, 32, false }, // tries to span two noncontiguous
{ 120, 10000, 33, true }, // > 8-bit
{ 20000, 20000, 34, true }, // > 8-bit
{ 0x10001, 0x10001, 35, true }, // > 16-bit
{ 27, -1, 36, false } // tests high < base
};
// Attempt to fill the entire space. The entire space must be filled with
// three stores because AddressType is signed for these tests, so RangeMap
// treats the size as signed and rejects sizes that appear to be negative.
// Even if these tests were run as unsigned, two stores would be needed
// to fill the space because the entire size of the space could only be
// described by using one more bit than would be present in AddressType.
const RangeTest range_tests_1[] = {
{ INT_MIN, INT_MAX, 50, true }, // From INT_MIN to -2, inclusive
{ -1, 2, 51, true }, // From -1 to 0, inclusive
{ 1, INT_MAX, 52, true }, // From 1 to INT_MAX, inclusive
{ INT_MIN, INT_MAX, 53, false }, // Can't fill the space twice
{ -1, 2, 54, false },
{ 1, INT_MAX, 55, false },
{ -3, 6, 56, false }, // -3 to 2, inclusive - spans 3 ranges
};
// A light round of testing to verify that RetrieveRange does the right
// the right thing at the extremities of the range when nothing is stored
// there. Checks are forced without storing anything at the extremities
// by setting size = 0.
const RangeTest range_tests_2[] = {
{ INT_MIN, 0, 100, false }, // makes RetrieveRange check low end
{ -1, 3, 101, true },
{ INT_MAX, 0, 102, false }, // makes RetrieveRange check high end
};
// Similar to the previous test set, but with a couple of ranges closer
// to the extremities.
const RangeTest range_tests_3[] = {
{ INT_MIN + 1, 1, 110, true },
{ INT_MAX - 1, 1, 111, true },
{ INT_MIN, 0, 112, false }, // makes RetrieveRange check low end
{ INT_MAX, 0, 113, false } // makes RetrieveRange check high end
};
// The range map is cleared between sets of tests listed here.
const RangeTestSet range_test_sets[] = {
{ range_tests_0, sizeof(range_tests_0) / sizeof(RangeTest) },
{ range_tests_1, sizeof(range_tests_1) / sizeof(RangeTest) },
{ range_tests_2, sizeof(range_tests_2) / sizeof(RangeTest) },
{ range_tests_3, sizeof(range_tests_3) / sizeof(RangeTest) },
{ range_tests_0, sizeof(range_tests_0) / sizeof(RangeTest) } // Run again
};
// Maintain the range map in a pointer so that deletion can be meaningfully
// tested.
auto_ptr<TestMap> range_map(new TestMap());
// Run all of the test sets in sequence.
unsigned int range_test_set_count = sizeof(range_test_sets) /
sizeof(RangeTestSet);
for (unsigned int range_test_set_index = 0;
range_test_set_index < range_test_set_count;
++range_test_set_index) {
const RangeTest* range_tests =
range_test_sets[range_test_set_index].range_tests;
unsigned int range_test_count =
range_test_sets[range_test_set_index].range_test_count;
// Run the StoreRange test, which validates StoreRange and initializes
// the RangeMap with data for the RetrieveRange test.
int stored_count = 0; // The number of ranges successfully stored
for (unsigned int range_test_index = 0;
range_test_index < range_test_count;
++range_test_index) {
const RangeTest* range_test = &range_tests[range_test_index];
if (!StoreTest(range_map.get(), range_test))
return false;
if (range_test->expect_storable)
++stored_count;
}
// There should be exactly one CountedObject for everything successfully
// stored in the RangeMap.
if (CountedObject::count() != stored_count) {
fprintf(stderr, "FAILED: "
"stored object counts don't match, expected %d, observed %d\n",
stored_count,
CountedObject::count());
return false;
}
// Run the RetrieveRange test
for (unsigned int range_test_index = 0;
range_test_index < range_test_count;
++range_test_index) {
const RangeTest* range_test = &range_tests[range_test_index];
if (!RetrieveTest(range_map.get(), range_test))
return false;
}
// Clear the map between test sets. If this is the final test set,
// delete the map instead to test destruction.
if (range_test_set_index < range_test_set_count - 1)
range_map->Clear();
else
range_map.reset();
// Test that all stored objects are freed when the RangeMap is cleared
// or deleted.
if (CountedObject::count() != 0) {
fprintf(stderr, "FAILED: "
"did not free all objects after %s, %d still allocated\n",
range_test_set_index < range_test_set_count - 1 ? "clear"
: "delete",
CountedObject::count());
return false;
}
}
return true;
}
int main(int argc, char** argv) {
return RunTests() ? 0 : 1;
}

BIN
src/processor/testdata/minidump1.dmp vendored Normal file

Binary file not shown.

3734
src/processor/testdata/minidump1.out vendored Normal file

File diff suppressed because one or more lines are too long