This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 1/4] Create new target "kdump" which uses libkdumpfile: https://github.com/ptesarik/libkdumpfile to access contents of compressed kernel dump.


---
 LICENSE                              |  340 +++++++
 gdb/Makefile.in                      |   13 +-
 gdb/c-typeprint.c                    |    6 +
 gdb/c-valprint.c                     |    6 +
 gdb/cli/cli-cmds.c                   |   34 +-
 gdb/configure.ac                     |   47 +-
 gdb/data-directory/Makefile.in       |    1 +
 gdb/disasm.c                         |  110 ++
 gdb/disasm.h                         |    1 +
 gdb/kdump.c                          | 1867 ++++++++++++++++++++++++++++++++++
 gdb/mi/mi-out.c                      |    3 +-
 gdb/python/lib/gdb/kdump/__init__.py |   20 +
 gdb/python/py-block.c                |  102 ++
 gdb/typeprint.c                      |    9 +-
 gdb/typeprint.h                      |    2 +
 15 files changed, 2541 insertions(+), 20 deletions(-)
 create mode 100644 LICENSE
 create mode 100644 gdb/kdump.c
 create mode 100644 gdb/python/lib/gdb/kdump/__init__.py

diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d6a9326
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,340 @@
+GNU GENERAL PUBLIC LICENSE
+                       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+                            NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    {description}
+    Copyright (C) {year}  {fullname}
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) year name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  {signature of Ty Coon}, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
+
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index dfaa8a3..3c7518a 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -136,6 +136,7 @@ CC_LD=$(COMPILER)
 INCLUDE_DIR =  $(srcdir)/../include
 INCLUDE_CFLAGS = -I$(INCLUDE_DIR)
 
+LIBKDUMPFILE_LDFLAGS = @LIBKDUMPFILE_LDFLAGS@
 # Where is the "-liberty" library?  Typically in ../libiberty.
 LIBIBERTY = ../libiberty/libiberty.a
 
@@ -533,7 +534,7 @@ CONFIG_UNINSTALL = @CONFIG_UNINSTALL@
 HAVE_NATIVE_GCORE_TARGET = @HAVE_NATIVE_GCORE_TARGET@
 
 # -I. for config files.
-# -I$(srcdir) for gdb internal headers.
+# >I$(srcdir) for gdb internal headers.
 # -I$(srcdir)/config for more generic config files.
 
 # It is also possible that you will need to add -I/usr/include/sys if
@@ -558,7 +559,7 @@ CFLAGS = @CFLAGS@
 # are sometimes a little generic, we think that the risk of collision
 # with other header files is high.  If that happens, we try to mitigate
 # a bit the consequences by putting the Python includes last in the list.
-INTERNAL_CPPFLAGS = @CPPFLAGS@ @GUILE_CPPFLAGS@ @PYTHON_CPPFLAGS@
+INTERNAL_CPPFLAGS = @CPPFLAGS@ @GUILE_CPPFLAGS@ @PYTHON_CPPFLAGS@ @LIBKDUMPFILE_CPPFLAGS@
 
 # Need to pass this to testsuite for "make check".  Probably should be
 # consistent with top-level Makefile.in and gdb/testsuite/Makefile.in
@@ -570,7 +571,7 @@ INTERNAL_CFLAGS_BASE = \
 	$(CFLAGS) $(GLOBAL_CFLAGS) $(PROFILE_CFLAGS) \
 	$(GDB_CFLAGS) $(OPCODES_CFLAGS) $(READLINE_CFLAGS) $(ZLIBINC) \
 	$(BFD_CFLAGS) $(INCLUDE_CFLAGS) $(LIBDECNUMBER_CFLAGS) \
-	$(INTL_CFLAGS) $(INCGNU) $(ENABLE_CFLAGS) $(INTERNAL_CPPFLAGS)
+	$(INTL_CFLAGS) $(INCGNU) $(ENABLE_CFLAGS) $(INTERNAL_CPPFLAGS) 
 INTERNAL_WARN_CFLAGS = $(INTERNAL_CFLAGS_BASE) $(GDB_WARN_CFLAGS)
 INTERNAL_CFLAGS = $(INTERNAL_WARN_CFLAGS) $(GDB_WERROR_CFLAGS)
 
@@ -594,7 +595,7 @@ CLIBS = $(SIM) $(READLINE) $(OPCODES) $(BFD) $(ZLIB) $(INTL) $(LIBIBERTY) $(LIBD
 	$(XM_CLIBS) $(NAT_CLIBS) $(GDBTKLIBS) \
 	@LIBS@ @GUILE_LIBS@ @PYTHON_LIBS@ \
 	$(LIBEXPAT) $(LIBLZMA) $(LIBBABELTRACE) $(LIBIPT) \
-	$(LIBIBERTY) $(WIN32LIBS) $(LIBGNU)
+	$(LIBIBERTY) $(WIN32LIBS) $(LIBGNU) $(LIBKDUMPFILE_LDFLAGS)
 CDEPS = $(XM_CDEPS) $(NAT_CDEPS) $(SIM) $(BFD) $(READLINE_DEPS) \
 	$(OPCODES) $(INTL_DEPS) $(LIBIBERTY) $(CONFIG_DEPS) $(LIBGNU)
 
@@ -833,7 +834,7 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \
 	build-id.c buildsym.c \
 	c-exp.y c-lang.c c-typeprint.c c-valprint.c c-varobj.c \
 	charset.c common/cleanups.c cli-out.c coffread.c coff-pe-read.c \
-	complaints.c completer.c continuations.c corefile.c corelow.c \
+	complaints.c completer.c continuations.c corefile.c corelow.c @KDUMP_SOURCES@ \
 	cp-abi.c cp-support.c cp-namespace.c cp-valprint.c \
 	d-exp.y d-lang.c d-valprint.c \
 	cp-name-parser.y \
@@ -1021,7 +1022,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
 	blockframe.o breakpoint.o break-catch-sig.o break-catch-throw.o \
 	break-catch-syscall.o \
 	findvar.o regcache.o cleanups.o \
-	charset.o continuations.o corelow.o disasm.o dummy-frame.o dfp.o \
+	charset.o continuations.o corelow.o @KDUMP_OBJS@ disasm.o dummy-frame.o dfp.o \
 	source.o value.o eval.o valops.o valarith.o valprint.o printcmd.o \
 	block.o symtab.o psymtab.o symfile.o symfile-debug.o symmisc.o \
 	linespec.o dictionary.o \
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 421b720..283612f 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -1105,6 +1105,12 @@ c_type_print_base (struct type *type, struct ui_file *stream,
 		      }
 		  }
 
+		if (flags->print_offsets == 1) {
+		  if (TYPE_CODE(type) == TYPE_CODE_STRUCT)
+   		    fprintf_filtered (stream, "[0x%03x] ", TYPE_FIELD(type, i).loc.bitpos >> 3);
+		  else
+   		    fprintf_filtered (stream, "         ");
+		}
 		print_spaces_filtered (level + 4, stream);
 		if (field_is_static (&TYPE_FIELD (type, i)))
 		  fprintf_filtered (stream, "static ");
diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c
index 8d8b744..89e86df 100644
--- a/gdb/c-valprint.c
+++ b/gdb/c-valprint.c
@@ -270,6 +270,12 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
 	{
 	  int want_space;
 
+		if (TYPE_CODE(elttype) == TYPE_CODE_STRUCT) {
+			if (TYPE_TAG_NAME(elttype))
+				fprintf_filtered (stream, _("(struct %s*) "), TYPE_TAG_NAME(elttype));
+			else if (TYPE_NAME(elttype))
+				fprintf_filtered (stream, _("(struct %s*) "), TYPE_NAME(elttype));
+		}
 	  addr = unpack_pointer (type, valaddr + embedded_offset);
 	print_unpacked_pointer:
 
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 2ec2dd3..734b3f7 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -55,6 +55,7 @@
 #endif
 
 #include <fcntl.h>
+#include "mi/mi-out.h"
 
 /* Prototypes for local command functions */
 
@@ -1092,17 +1093,28 @@ print_disassembly (struct gdbarch *gdbarch, const char *name,
   if (!tui_is_window_visible (DISASSEM_WIN))
 #endif
     {
-      printf_filtered ("Dump of assembler code ");
-      if (name != NULL)
-        printf_filtered ("for function %s:\n", name);
-      else
-        printf_filtered ("from %s to %s:\n",
-			 paddress (gdbarch, low), paddress (gdbarch, high));
+      if (flags & DISASSEMBLY_HACK) {
+	struct ui_out *out;
+	out = mi_out_new (1);
+	//mi_begin(out, ui_out_type_tuple, 0, "aaaaa");
+	ui_out_begin (out, ui_out_type_tuple, NULL);
+	gdb_disassembly (gdbarch, out, 0, flags & ~DISASSEMBLY_OMIT_FNAME, -1, low, high);
+	ui_out_end (out, ui_out_type_tuple);
+	mi_out_put (out, gdb_stdout);
+	ui_out_destroy (out);
+      } else {
+	printf_filtered ("Dump of assembler code ");
+	if (name != NULL)
+	  printf_filtered ("for function %s:\n", name);
+	else
+	  printf_filtered ("from %s to %s:\n",
+			   paddress (gdbarch, low), paddress (gdbarch, high));
 
-      /* Dump the specified range.  */
-      gdb_disassembly (gdbarch, current_uiout, 0, flags, -1, low, high);
+	/* Dump the specified range.  */
+	gdb_disassembly (gdbarch, current_uiout, 0, flags, -1, low, high);
 
-      printf_filtered ("End of assembler dump.\n");
+	printf_filtered ("End of assembler dump.\n");
+      }
       gdb_flush (gdb_stdout);
     }
 #if defined(TUI)
@@ -1186,6 +1198,9 @@ disassemble_command (char *arg, int from_tty)
 	    case 'r':
 	      flags |= DISASSEMBLY_RAW_INSN;
 	      break;
+	    case 'h':
+	      flags |= DISASSEMBLY_HACK;
+	      break;
 	    default:
 	      error (_("Invalid disassembly modifier."));
 	    }
@@ -1856,6 +1871,7 @@ Disassemble a specified section of memory.\n\
 Default is the function surrounding the pc of the selected frame.\n\
 With a /m modifier, source lines are included (if available).\n\
 With a /r modifier, raw instructions in hex are included.\n\
+With a /h modifier, MI2-formatted extra informations are dumped.\n\
 With a single argument, the function surrounding that address is dumped.\n\
 Two arguments (separated by a comma) are taken as a range of memory to dump,\n\
   in the form of \"start,end\", or \"start,+length\".\n\
diff --git a/gdb/configure.ac b/gdb/configure.ac
index a40860a..41f5e04 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1032,7 +1032,7 @@ AM_CONDITIONAL(HAVE_PYTHON, test "${have_libpython}" != no)
 # -------------------- #
 # Check for libguile.  #
 # -------------------- #
-
+data
 dnl Utility to simplify finding libguile.
 dnl $1 = pkg-config-program
 dnl $2 = space-separate list of guile versions to try
@@ -2465,6 +2465,51 @@ else
   fi
 fi
 
+AC_ARG_WITH(libkdumpfile,
+  AC_HELP_STRING([--with-libkdumpfile], [include support for linux kernel dumps (auto/yes/no)]),
+  [], [with_libkdumpfile=auto])
+AC_MSG_CHECKING([whether to use libkdumpfile])
+AC_MSG_RESULT([$with_libkdumpfile])
+
+if test "x$with_libkdumpfile" = "xno"; then
+  AC_MSG_WARN([linux kernel dumps support disabled; GDB is unable to read kdump.])
+else
+  saved_CFLAGS=$CFLAGS
+  CFLAGS="$CFLAGS -Werror"
+  AC_LIB_HAVE_LINKFLAGS([kdumpfile], [],
+			[#include <kdumpfile.h>
+			static kdump_ctx *dump_ctx;])
+  CFLAGS=$saved_CFLAGS
+
+  new_CPPFLAGS=`${pkg_config} --cflags libkdumpfile`
+  if test $? != 0; then
+    AC_MSG_WARN([failure running pkg-config --cflags libkdumpfile}])
+  fi
+  new_LIBS=`${pkg_config} --libs libkdumpfile`
+  if test $? != 0; then
+    AC_MSG_WARN([failure running pkg-config --libs libkdumpfile}])
+  fi
+   
+  if test "$HAVE_LIBKDUMPFILE" != yes; then
+     if test "$with_libkdumpfile" = yes; then
+       AC_MSG_ERROR([libkdumpfile is missing or unusable])
+     else
+       AC_MSG_WARN([libkdumpfile is missing or unusable; GDB is unable to kdump.])
+     fi
+  else
+    LIBKDUMPFILE_CPPFLAGS=${new_CPPFLAGS}    	
+    LIBKDUMPFILE_LDFLAGS=${new_LIBS}    	
+    KDUMP_SOURCES=kdump.c
+    KDUMP_OBJS=kdump.o
+    AC_SUBST(KDUMP_OBJS)
+    AC_SUBST(KDUMP_SOURCES)
+    AC_SUBST(LIBKDUMPFILE_CPPFLAGS)
+    AC_SUBST(LIBKDUMPFILE_LDFLAGS)
+  fi
+fi
+
+
+
 # If nativefile (NAT_FILE) is not set in config/*/*.m[ht] files, we link
 # to an empty version.
 
diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in
index abca534..fe2733d 100644
--- a/gdb/data-directory/Makefile.in
+++ b/gdb/data-directory/Makefile.in
@@ -73,6 +73,7 @@ PYTHON_FILE_LIST = \
 	gdb/command/pretty_printers.py \
 	gdb/command/prompt.py \
 	gdb/command/explore.py \
+	gdb/kdump/__init__.py \
 	gdb/function/__init__.py \
 	gdb/function/caller_is.py \
 	gdb/function/strfns.py \
diff --git a/gdb/disasm.c b/gdb/disasm.c
index 483df01..8304769 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -24,6 +24,10 @@
 #include "disasm.h"
 #include "gdbcore.h"
 #include "dis-asm.h"
+#include "ui-out.h"
+#include "c-lang.h"
+#include "block.h"
+#include "typeprint.h"
 
 /* Disassemble functions.
    FIXME: We should get rid of all the duplicate code in gdb that does
@@ -92,6 +96,42 @@ compare_lines (const void *mle1p, const void *mle2p)
   return val;
 }
 
+
+struct lst {
+  const void *data;
+  struct lst *next;
+};
+
+static void lst_new(struct lst **l)
+{
+  *l = NULL;
+}
+static struct lst *lst_add(struct lst *l, const void *data)
+{
+  struct lst *n = malloc(sizeof (*n));
+  n->next = l;
+  n->data = data;
+  return n;
+}
+
+static int lst_has(struct lst *l, const void *data)
+{
+  for (; l != NULL && l->data != data; l = l->next);
+  return l?1:0;
+}
+
+static void lst_free(struct lst **l)
+{
+  struct lst *n;
+
+  while(*l) {
+    n = (*l)->next;
+    free (* l);
+    *l = NULL;
+    l = &n;
+  }                                                                                                                                                          
+}
+
 static int
 dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
 	    struct disassemble_info * di,
@@ -106,6 +146,12 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
   int offset;
   int line;
   struct cleanup *ui_out_chain;
+  struct lst *blocks;
+  struct symtab_and_line sal;
+  const struct block *block;
+
+  if (flags & DISASSEMBLY_HACK) 
+    lst_new (& blocks);
 
   for (pc = low; pc < high;)
     {
@@ -122,6 +168,19 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
 	}
       ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
 
+      if (flags & DISASSEMBLY_HACK) {
+	block = block_for_pc (pc);                                                                                                                               
+	if (block && ! lst_has(blocks, block)) {
+	  blocks = lst_add (blocks, block);
+	}
+
+	sal = find_pc_line (pc, 1);                                                                                                                              
+        if (sal.symtab && sal.symtab->filename) {
+	  ui_out_field_string (uiout, "file-name", sal.symtab->filename);
+	  ui_out_field_int (uiout, "file-line", sal.line);
+	}
+      }
+
       if ((flags & DISASSEMBLY_OMIT_PC) == 0)
 	ui_out_text (uiout, pc_prefix (pc));
       ui_out_field_core_addr (uiout, "address", gdbarch, pc);
@@ -182,6 +241,57 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
       do_cleanups (ui_out_chain);
       ui_out_text (uiout, "\n");
     }
+
+  if (flags & DISASSEMBLY_HACK) {
+    struct lst *l;
+    ui_out_end (uiout, ui_out_type_list);
+    ui_out_begin (uiout, ui_out_type_list, "blocks");
+    for (l = blocks; l; l = l->next) {
+      struct dict_iterator iter;
+      void *v;
+      block = (struct block*)l->data;
+      ui_out_begin (uiout, ui_out_type_tuple, NULL);
+      ui_out_field_core_addr (uiout, "begin", gdbarch, block->startaddr);
+      ui_out_field_core_addr (uiout, "end", gdbarch, block->endaddr);
+
+      if (block_inlined_p (block)) {
+	ui_out_field_string (uiout, "inlined", SYMBOL_NATURAL_NAME(BLOCK_FUNCTION(block)));
+      }
+
+      ui_out_begin (uiout, ui_out_type_list, "variables");
+      v = dict_iterator_first(block->dict, &iter);                                                                                               
+      while (v != NULL) {
+	struct symbol *ss = (struct symbol*)v;                                    
+	struct type *typ = SYMBOL_TYPE(ss);
+        struct ui_file *mem = mem_fileopen ();
+        struct cleanup *cleanups = make_cleanup_ui_file_delete (mem);
+
+	c_print_type(typ, SYMBOL_NATURAL_NAME(ss), mem, 1, 4, &type_print_raw_options);
+
+	ui_out_begin (uiout, ui_out_type_tuple, NULL);
+
+	ui_out_field_stream (uiout, "variable", mem);
+
+	ui_file_rewind (mem);
+
+	if (SYMBOL_COMPUTED_OPS(ss) != NULL) {
+	  SYMBOL_COMPUTED_OPS(ss)->describe_location(ss, block->startaddr, mem);
+	  ui_out_field_stream (uiout, "dwarf", mem);
+	}
+        ui_out_end (uiout, ui_out_type_tuple);
+	//ui_file_delete (mem);
+        do_cleanups (cleanups);
+	v = dict_iterator_next(&iter);
+      } 
+      ui_out_end (uiout, ui_out_type_list);
+
+      ui_out_end (uiout, ui_out_type_tuple);
+
+    }
+
+    lst_free (& blocks);
+  }
+
   return num_displayed;
 }
 
diff --git a/gdb/disasm.h b/gdb/disasm.h
index a91211e..ef43994 100644
--- a/gdb/disasm.h
+++ b/gdb/disasm.h
@@ -26,6 +26,7 @@
 #define DISASSEMBLY_OMIT_FNAME	(0x1 << 2)
 #define DISASSEMBLY_FILENAME	(0x1 << 3)
 #define DISASSEMBLY_OMIT_PC	(0x1 << 4)
+#define DISASSEMBLY_HACK   	(0x1 << 5)
 
 struct gdbarch;
 struct ui_out;
diff --git a/gdb/kdump.c b/gdb/kdump.c
new file mode 100644
index 0000000..b7b0ef5
--- /dev/null
+++ b/gdb/kdump.c
@@ -0,0 +1,1867 @@
+/* Core dump and executable file functions below target vector, for GDB.
+
+ Copyright (C) 1986-2015 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "arch-utils.h"
+#include <signal.h>
+#include <fcntl.h>
+#ifdef HAVE_SYS_FILE_H
+#include <sys/file.h>		/* needed for F_OK and friends */
+#endif
+#include "frame.h"		/* required by inferior.h */
+
+#include "symtab.h"
+#include "regcache.h"
+#include "memattr.h"
+#include "language.h"
+#include "command.h"
+#include "gdbcmd.h"
+#include "inferior.h"
+#include "infrun.h"
+#include "command.h"
+#include "bfd.h"
+#include "target.h"
+#include "gdbcore.h"
+#include "gdbthread.h"
+#include "regcache.h"
+#include "regset.h"
+#include "symfile.h"
+#include "exec.h"
+#include "readline/readline.h"
+#include "exceptions.h"
+#include "solib.h"
+#include "filenames.h"
+#include "progspace.h"
+#include "objfiles.h"
+#include "gdb_bfd.h"
+#include "completer.h"
+#include "filestuff.h"
+#include "s390-linux-tdep.h"
+#include "kdumpfile.h"
+#include "minsyms.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+
+#include <dirent.h>
+#include <endian.h>
+
+#ifndef O_LARGEFILE
+#define O_LARGEFILE 0
+#endif
+typedef unsigned long long offset;
+#define NULL_offset 0LL
+#define F_BIG_ENDIAN     1
+#define F_LITTLE_ENDIAN  2
+#define F_UNKN_ENDIAN    4
+
+unsigned long long kt_int_value (void *buff);
+unsigned long long kt_ptr_value (void *buff);
+
+int kt_hlist_head_for_each_node (char *addr, int(*func)(void *,offset), void *data);
+
+#define kt_list_head_for_each(addr,head,lhb, _nxt) for((_nxt = kt_ptr_value(lhb)), kdump_type_alloc((struct kdump_type*)&kt_list_head, _nxt, 0, lhb);\
+	(_nxt = kt_ptr_value(lhb)) != head; \
+	kdump_type_alloc((struct kdump_type*)&kt_list_head, _nxt, 0, lhb))
+
+static struct target_ops core_ops;
+
+static kdump_ctx *dump_ctx = NULL;
+
+struct gdbarch *kdump_gdbarch = NULL;
+
+struct target_ops *kdump_target = NULL;
+
+static void init_core_ops (void);
+
+void _initialize_kdump (void);
+
+static void core_close (struct target_ops *self);
+
+typedef unsigned long long offset;
+
+#define KDUMP_TYPE const char *_name; int _size; int _offset; struct type *_origtype
+#define GET_GDB_TYPE(typ) types. typ ._origtype
+#define GET_TYPE_SIZE(typ) (TYPE_LENGTH(GET_GDB_TYPE(typ)))
+#define MEMBER_OFFSET(type,member) types. type. member
+#define KDUMP_TYPE_ALLOC(type) kdump_type_alloc(GET_GDB_TYPE(type))
+#define KDUMP_TYPE_GET(type,off,where) kdump_type_get(GET_GDB_TYPE(type), off, 0, where)
+#define KDUMP_TYPE_FREE(where) free(where)
+#define SYMBOL(var,name) do { var = lookup_symbol(name, NULL, VAR_DOMAIN, NULL); if (! var) { fprintf(stderr, "Cannot lookup_symbol(" name ")\n"); goto error; } } while(0)
+#define OFFSET(x) (types.offsets. x)
+
+#define MAXSYMNAME 256
+
+#define GET_REGISTER_OFFSET(reg) (MEMBER_OFFSET(user_regs_struct,reg)/GET_TYPE_SIZE(_voidp))
+#define GET_REGISTER_OFFSET_pt(reg) (MEMBER_OFFSET(pt_regs,reg)/GET_TYPE_SIZE(_voidp))
+
+#define list_for_each(pos, head) \
+	for (pos = kt_ptr_value(head); pos != (head); KDUMP_TYPE_GET(_voidp,pos,&pos)
+
+#define list_head_for_each(head,lhb, _nxt) for((_nxt = kt_ptr_value(lhb)), KDUMP_TYPE_GET(list_head, _nxt, lhb);\
+	(_nxt = kt_ptr_value(lhb)) != head; \
+	KDUMP_TYPE_GET(list_head, _nxt, lhb))
+
+enum x86_64_regs {
+	reg_RAX = 0,
+	reg_RCX = 2,
+	reg_RDX = 1,
+	reg_RBX = 3,
+	reg_RBP = 6,
+	reg_RSI = 4,
+	reg_RDI = 5,
+	reg_RSP = 7,
+	reg_R8 = 8,
+	reg_R9 = 9,
+	reg_R10 = 10,
+	reg_R11 = 11,
+	reg_R12 = 12,
+	reg_R13 = 13,
+	reg_R14 = 14,
+	reg_R15 = 15,
+	reg_RIP = 16,
+	reg_RFLAGS = 49,
+	reg_ES = 50,
+	reg_CS = 51,
+	reg_SS = 52,
+	reg_DS = 53,
+	reg_FS = 54,
+	reg_GS = 55,
+};
+
+int kt_hlist_head_for_each_node (char *addr, int(*func)(void *,offset), void *data);
+
+typedef enum {
+	ARCH_NONE,
+	ARCH_X86_64,
+	ARCH_S390X,
+	ARCH_PPC64LE,
+} t_arch;
+
+struct cpuinfo {
+	struct {
+		offset curr;
+	} rq;
+};
+
+struct {
+	struct {
+		KDUMP_TYPE;
+		offset prev;
+		offset next;
+	} list_head;
+
+	struct {
+		KDUMP_TYPE;
+		offset first;
+	} hlist_head;
+
+	struct {
+		KDUMP_TYPE;
+		offset next;
+	} hlist_node;
+
+	struct {
+		KDUMP_TYPE;
+	} _int;
+
+	struct {
+		KDUMP_TYPE;
+	} _voidp;
+
+	struct {
+		KDUMP_TYPE;
+
+		offset nr;
+		offset pid_chain;
+	} upid;
+
+	struct {
+		KDUMP_TYPE;
+
+		offset pid;
+		offset pids;
+		offset stack;
+		offset tasks;
+		offset thread;
+		offset thread_group;
+		offset state;
+		offset comm;
+	} task_struct;
+
+	struct {
+		KDUMP_TYPE;
+		offset sp;
+	} thread_struct;
+
+	struct {
+		KDUMP_TYPE;
+		offset curr;
+		offset idle;
+	} rq;
+
+	struct {
+		KDUMP_TYPE;
+		offset r15;
+		offset r14;
+		offset r13;
+		offset r12;
+		offset bp;
+		offset bx;
+		offset r11;
+		offset r10;
+		offset r9;
+		offset r8;
+		offset ax;
+		offset cx;
+		offset dx;
+		offset si;
+		offset di;
+		offset orig_ax;
+		offset ip;
+		offset cs;
+		offset flags;
+		offset sp;
+		offset ss;
+		offset fs_base;
+		offset gs_base;
+		offset ds;
+		offset es;
+		offset fs;
+		offset gs;
+	} user_regs_struct;
+
+	struct pt_regs {
+		KDUMP_TYPE;
+		offset r15;
+		offset r14;
+		offset r13;
+		offset r12;
+		offset bp;
+		offset bx;
+		offset r11;
+		offset r10;
+		offset r9;
+		offset r8;
+		offset ax;
+		offset cx;
+		offset dx;
+		offset si;
+		offset di;
+		offset orig_ax;
+		offset ip;
+		offset cs;
+		offset flags;
+		offset sp;
+		offset ss;		
+	} pt_regs;
+
+	struct ppc_pt_regs {
+		KDUMP_TYPE;
+                offset gpr00;
+                offset gpr01;
+                offset gpr02;
+                offset gpr03;
+                offset gpr04;
+                offset gpr05;
+                offset gpr06;
+                offset gpr07;
+                offset gpr08;
+                offset gpr09;
+                offset gpr10;
+                offset gpr11;
+                offset gpr12;
+                offset gpr13;
+                offset gpr14;
+                offset gpr15;
+                offset gpr16;
+                offset gpr17;
+                offset gpr18;
+                offset gpr19;
+                offset gpr20;
+                offset gpr21;
+                offset gpr22;
+                offset gpr23;
+                offset gpr24;
+                offset gpr25;
+                offset gpr26;
+                offset gpr27;
+                offset gpr28;
+                offset gpr29;
+                offset gpr30;
+                offset gpr31;
+                offset nip;
+                offset msr;
+                offset or3;
+                offset ctr;
+                offset lr;
+                offset xer;
+                offset ccr;
+                offset mq;
+                offset dar;
+                offset dsisr;
+                offset rx1;
+                offset rx2;
+                offset rx3;
+                offset rx4;
+                offset rx5;
+                offset rx6;
+                offset rx7;
+	} ppc_pt_regs;
+
+	struct {
+		KDUMP_TYPE;
+		offset list;
+		offset version;
+		offset srcversion;
+		offset name;
+		offset module_core;
+	} module;
+
+
+	int flags;
+	t_arch arch;
+
+	struct {
+		offset percpu_start;
+		offset percpu_end;
+		offset *percpu_offsets;
+	} offsets;
+
+	struct cpuinfo *cpu;
+	int ncpus;
+} types;
+
+struct task_info {
+	offset task_struct;
+	offset sp;
+	offset ip;
+	int pid;
+	int cpu;
+	offset rq;
+};
+
+enum {
+	T_STRUCT = 1,
+	T_BASE,
+	T_REF
+};
+
+static void free_task_info(struct private_thread_info *addr)
+{
+	struct task_info *ti = (struct task_info*)addr;
+	free(ti);
+}
+
+static struct type *my_lookup_struct (const char *name, const struct block *block)
+{
+  struct symbol *sym;
+
+  sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
+
+  if (sym == NULL)
+    {
+	return NULL;
+    }
+  if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
+    {
+      warning(_("This context has class, union or enum %s, not a struct."), name);
+      return NULL;
+    }
+  return (SYMBOL_TYPE (sym));
+}
+
+
+unsigned long long kt_int_value (void *buff)
+{
+	unsigned long long val;
+
+	if (GET_TYPE_SIZE(_int) == 4) {
+		val = *(int32_t*)buff;
+		if (types.flags & F_BIG_ENDIAN) val = be32toh(val);
+	} else {
+		val = *(int64_t*)buff;
+		if (types.flags & F_BIG_ENDIAN) val = be64toh(val);
+	}
+
+	return val;
+}
+
+unsigned long long kt_ptr_value (void *buff)
+{
+	unsigned long long val;
+	
+	if (GET_TYPE_SIZE(_voidp) == 4) {
+		val = (unsigned long long) *(uint32_t**)buff;
+		if (types.flags & F_BIG_ENDIAN) val = be32toh(val);
+	} else {
+		val = (unsigned long long) *(uint64_t**)buff;
+		if (types.flags & F_BIG_ENDIAN) val = be64toh(val);
+	}
+	return val;
+}
+static offset get_symbol_address(const char *sname);
+static offset get_symbol_address(const char *sname)
+{
+	struct symbol *ss;
+	const struct language_defn *lang;
+	struct bound_minimal_symbol bms;
+	struct value *val;
+	offset off;
+
+	bms = lookup_minimal_symbol(sname, NULL, NULL);
+	if (bms.minsym != NULL) {
+		return ((offset)BMSYMBOL_VALUE_ADDRESS(bms));
+	}
+	ss = lookup_global_symbol(sname, NULL, ALL_DOMAIN);
+	if (! ss) {
+		ss = lookup_static_symbol(sname, ALL_DOMAIN);
+		if (! ss) return NULL_offset ;
+	}
+	lang  = language_def (SYMBOL_LANGUAGE (ss));
+	val = lang->la_read_var_value (ss, NULL);
+	if (! val) {
+		return NULL_offset;
+	}
+
+		off = (offset) value_address(val);
+		return off;
+	if (TYPE_CODE(value_type(val)) == TYPE_CODE_ENUM) {
+		return (offset) value_as_long(val);
+	} else {
+		off = (offset) value_address(val);
+		return off;
+	}
+}
+static offset get_symbol_value(const char *sname);
+static offset get_symbol_value(const char *sname)
+{
+	struct symbol *ss;
+	const struct language_defn *lang;
+	struct value *val;
+	offset off;
+	ss = lookup_global_symbol(sname, NULL, VAR_DOMAIN);
+	if (! ss) {
+		ss = lookup_static_symbol(sname, VAR_DOMAIN);
+		if (! ss) return NULL_offset ;
+	}
+	lang  = language_def (SYMBOL_LANGUAGE (ss));
+	val = lang->la_read_var_value (ss, NULL);
+	if (! val) {
+		return NULL_offset;
+	}
+
+	if (TYPE_CODE(value_type(val)) == TYPE_CODE_ENUM) {
+		return (offset) value_as_long(val);
+	} else {
+		off = (offset) value_address(val);
+		return off;
+	}
+}
+
+/**
+ * Searches the gdb for the type of specified name of the specified kind.
+ *
+ * @param _type on successfull return contains pointer to type
+ * @param size on successfull return contains type size
+ * @param origname the name of type
+ * @param origtype T_STRUCT or T_REF or T_BASE
+ *
+ * @return 0 on success
+ */
+static int kdump_type_init (struct type **_type, int *size, const char *origname, int origtype)
+{
+	struct type *t;
+
+	if (origtype == T_STRUCT)  {
+		t = my_lookup_struct(origname, NULL);
+	} else if (origtype == T_REF) {
+		struct type *dt;
+ 		dt = lookup_typename(current_language, kdump_gdbarch, origname, NULL, 0);
+		if (dt == NULL) {
+			warning(_("Cannot lookup dereferenced type %s\n"), origname);
+			t = NULL;
+		} else {
+			t = lookup_reference_type(dt);
+		}
+	} else
+		t = lookup_typename(current_language, kdump_gdbarch, origname, NULL, 0);
+
+	if (t == NULL) {
+		warning(_("Cannot lookup(%s)\n"), origname);
+		return 1;
+	}
+
+	*_type = t;
+	*size = TYPE_LENGTH(t);
+
+	return 0;
+}
+
+static int kdump_type_member_init (struct type *type, const char *name, offset *poffset)
+{
+	int i;
+	struct field *f;
+	f = TYPE_FIELDS(type);
+	for (i = 0; i < TYPE_NFIELDS(type); i ++) {
+		if (! strcmp(f->name, name)) {
+			*poffset = (f->loc.physaddr >> 3);
+			return 0;
+		}
+		f++;
+	}
+	return -1;
+}
+
+static void *kdump_type_alloc(struct type *type)
+{
+	int allocated = 0;
+	void *buff;
+
+	allocated = 1;
+	buff = malloc(TYPE_LENGTH(type));
+	if (buff == NULL) {
+		warning(_("Cannot allocate memory of %d length\n"), (int)TYPE_LENGTH(type));
+		return NULL;
+	}
+	return buff;
+}
+
+static int kdump_type_get(struct type *type, offset addr, int pos, void *buff)
+{
+	if (target_read_raw_memory(addr + (TYPE_LENGTH(type)*pos), buff, TYPE_LENGTH(type))) {
+		warning(_("Cannot read target memory of %d length\n"), (int)TYPE_LENGTH(type));
+		return 1;
+	}
+	return 0;
+}
+
+int kdump_types_init(int flags);
+int kdump_types_init(int flags)
+{
+	int ret = 1;
+
+	types.flags = flags;
+
+	#define INIT_STRUCT(name) if(kdump_type_init(&types. name ._origtype, &types. name ._size, #name, T_STRUCT)) { fprintf(stderr, "Cannot find struct type \'%s\'", #name); break; }
+	#define INIT_STRUCT_(name) if(kdump_type_init(&types. name ._origtype, &types. name ._size, #name, T_STRUCT)) {  }
+	#define INIT_STRUCT__(name,nname) if(kdump_type_init(&types. nname ._origtype, &types. nname ._size, #name, T_STRUCT)) {  }
+	#define INIT_BASE_TYPE(name) if(kdump_type_init(&types. name ._origtype, &types. name ._size, #name, T_BASE)) { fprintf(stderr, "Cannot base find type \'%s\'", #name); break; }
+	/** initialize base type and supply its name */
+	#define INIT_BASE_TYPE_(name,tname) if(kdump_type_init(&types. tname ._origtype, &types. tname ._size, #name, T_BASE)) { fprintf(stderr, "Cannot base find type \'%s\'", #name); break; }
+	#define INIT_REF_TYPE(name) if(kdump_type_init(&types. name ._origtype, &types. name ._size, #name, T_REF)) { fprintf(stderr, "Cannot ref find type \'%s\'", #name); break; }
+	#define INIT_REF_TYPE_(name,tname) if(kdump_type_init(&types. tname ._origtype, &types. tname ._size, #name, T_REF)) { fprintf(stderr, "Cannot ref find type \'%s\'", #name); break; }
+	#define INIT_STRUCT_MEMBER(sname,mname) if(kdump_type_member_init(types. sname ._origtype, #mname, &types. sname . mname)) { break; }
+
+	/** initialize member with different name than the containing one */
+	#define INIT_STRUCT_MEMBER_(sname,mname,mmname) if(kdump_type_member_init(types. sname ._origtype, #mname, &types. sname . mmname)) { break; }
+
+	/** don't fail if the member is not present */
+	#define INIT_STRUCT_MEMBER__(sname,mname) kdump_type_member_init(types. sname ._origtype, #mname, &types. sname . mname)
+	do {
+		INIT_BASE_TYPE_(int,_int);
+		INIT_REF_TYPE_(void,_voidp);
+
+		INIT_STRUCT(list_head);
+		INIT_STRUCT_MEMBER(list_head,prev);
+		INIT_STRUCT_MEMBER(list_head,next);
+
+		INIT_STRUCT(hlist_head);
+		INIT_STRUCT_MEMBER(hlist_head,first);
+
+		INIT_STRUCT(hlist_node);
+		INIT_STRUCT_MEMBER(hlist_node,next);
+
+		INIT_STRUCT(upid);
+		INIT_STRUCT_MEMBER(upid,nr);
+		INIT_STRUCT_MEMBER(upid,pid_chain);
+
+		INIT_STRUCT(task_struct);
+		INIT_STRUCT_MEMBER(task_struct,pids);
+		INIT_STRUCT_MEMBER(task_struct,stack);
+		INIT_STRUCT_MEMBER(task_struct,tasks);
+		INIT_STRUCT_MEMBER(task_struct,thread);
+		INIT_STRUCT_MEMBER(task_struct,thread_group);
+		INIT_STRUCT_MEMBER(task_struct,pid);
+		INIT_STRUCT_MEMBER(task_struct,state);
+		INIT_STRUCT_MEMBER(task_struct,comm);
+
+		INIT_STRUCT(thread_struct);
+                MEMBER_OFFSET(thread_struct,sp) = 0;
+		INIT_STRUCT_MEMBER__(thread_struct,sp);
+                if (MEMBER_OFFSET(thread_struct,sp) == 0) {
+			INIT_STRUCT_MEMBER_(thread_struct,ksp,sp);
+		}
+
+		INIT_STRUCT(rq);
+
+		INIT_STRUCT_MEMBER(rq,curr);
+		INIT_STRUCT_MEMBER(rq,idle);
+
+		INIT_STRUCT_(user_regs_struct);
+		if (GET_GDB_TYPE(user_regs_struct)) {
+			INIT_STRUCT_MEMBER__(user_regs_struct, r15);
+			INIT_STRUCT_MEMBER__(user_regs_struct, r14);
+			INIT_STRUCT_MEMBER__(user_regs_struct, r13);
+			INIT_STRUCT_MEMBER__(user_regs_struct, r12);
+			INIT_STRUCT_MEMBER__(user_regs_struct, bp);
+			INIT_STRUCT_MEMBER__(user_regs_struct, bx);
+			INIT_STRUCT_MEMBER__(user_regs_struct, r11);
+			INIT_STRUCT_MEMBER__(user_regs_struct, r10);
+			INIT_STRUCT_MEMBER__(user_regs_struct, r9);
+			INIT_STRUCT_MEMBER__(user_regs_struct, r8);
+			INIT_STRUCT_MEMBER__(user_regs_struct, ax);
+			INIT_STRUCT_MEMBER__(user_regs_struct, cx);
+			INIT_STRUCT_MEMBER__(user_regs_struct, dx);
+			INIT_STRUCT_MEMBER__(user_regs_struct, si);
+			INIT_STRUCT_MEMBER__(user_regs_struct, di);
+			INIT_STRUCT_MEMBER__(user_regs_struct, orig_ax);
+			INIT_STRUCT_MEMBER__(user_regs_struct, ip);
+			INIT_STRUCT_MEMBER__(user_regs_struct, cs);
+			INIT_STRUCT_MEMBER__(user_regs_struct, flags);
+			INIT_STRUCT_MEMBER__(user_regs_struct, sp);
+			INIT_STRUCT_MEMBER__(user_regs_struct, ss);
+			INIT_STRUCT_MEMBER__(user_regs_struct, fs_base);
+			INIT_STRUCT_MEMBER__(user_regs_struct, gs_base);
+			INIT_STRUCT_MEMBER__(user_regs_struct, ds);
+			INIT_STRUCT_MEMBER__(user_regs_struct, es);
+			INIT_STRUCT_MEMBER__(user_regs_struct, fs);
+			INIT_STRUCT_MEMBER__(user_regs_struct, gs);
+		}
+
+		INIT_STRUCT(pt_regs);
+		INIT_STRUCT_MEMBER__(pt_regs, r15);
+		INIT_STRUCT_MEMBER__(pt_regs, r14);
+		INIT_STRUCT_MEMBER__(pt_regs, r13);
+		INIT_STRUCT_MEMBER__(pt_regs, r12);
+		INIT_STRUCT_MEMBER__(pt_regs, bp);
+		INIT_STRUCT_MEMBER__(pt_regs, bx);
+		INIT_STRUCT_MEMBER__(pt_regs, r11);
+		INIT_STRUCT_MEMBER__(pt_regs, r10);
+		INIT_STRUCT_MEMBER__(pt_regs, r9);
+		INIT_STRUCT_MEMBER__(pt_regs, r8);
+		INIT_STRUCT_MEMBER__(pt_regs, ax);
+		INIT_STRUCT_MEMBER__(pt_regs, cx);
+		INIT_STRUCT_MEMBER__(pt_regs, dx);
+		INIT_STRUCT_MEMBER__(pt_regs, si);
+		INIT_STRUCT_MEMBER__(pt_regs, di);
+		INIT_STRUCT_MEMBER__(pt_regs, orig_ax);
+		INIT_STRUCT_MEMBER__(pt_regs, ip);
+		INIT_STRUCT_MEMBER__(pt_regs, cs);
+		INIT_STRUCT_MEMBER__(pt_regs, flags);
+		INIT_STRUCT_MEMBER__(pt_regs, sp);
+		INIT_STRUCT_MEMBER__(pt_regs, ss);
+
+		INIT_STRUCT(module);
+		INIT_STRUCT_MEMBER(module, list);
+		INIT_STRUCT_MEMBER(module, version);
+		INIT_STRUCT_MEMBER(module, srcversion);
+		INIT_STRUCT_MEMBER(module, name);
+		INIT_STRUCT_MEMBER(module, module_core);
+
+		INIT_STRUCT__(pt_regs,ppc_pt_regs);
+		if (GET_GDB_TYPE(ppc_pt_regs)) {
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr00);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr01);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr02);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr03);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr04);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr05);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr06);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr07);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr08);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr09);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr10);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr11);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr12);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr13);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr14);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr15);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr16);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr17);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr18);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr19);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr20);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr21);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr22);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr23);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr24);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr25);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr26);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr27);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr28);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr29);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr30);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, gpr31);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, nip);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, msr);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, or3);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, ctr);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, lr);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, xer);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, ccr);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, mq);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, dar);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, dsisr);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, rx1);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, rx2);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, rx3);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, rx4);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, rx5);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, rx6);
+			INIT_STRUCT_MEMBER__(ppc_pt_regs, rx7);
+		}
+		ret = 0;
+	} while(0);
+
+	if (ret) {
+		fprintf(stderr, "Cannot init types\n");
+	}
+
+	return ret;
+}
+
+int kt_hlist_head_for_each_node (char *addr, int(*func)(void *,offset), void *data)
+{
+	char *b = NULL;
+	offset l;
+	int i = 0;
+	static int cnt = 0;
+	static int ccnt = 0;
+	ccnt ++;
+
+	b = KDUMP_TYPE_ALLOC(hlist_node);
+
+	l = kt_ptr_value((char*)addr + (size_t)MEMBER_OFFSET(hlist_head,first));
+	if (l == NULL_offset) return 0;
+	while(l != NULL_offset) {
+		
+		if (KDUMP_TYPE_GET (hlist_node, l, b)) {
+			fprintf(stderr, "Cannot kdump_type_alloc(kt_hlist_node)");
+			KDUMP_TYPE_FREE(b);
+			return -1;
+		}
+		if (func(data, l)) break;
+		l = kt_ptr_value((char*)b + (size_t)MEMBER_OFFSET(hlist_node,next));
+	}
+
+	if (b) free(b);
+	return 0;
+}
+
+static void
+core_close (struct target_ops *self)
+{
+	if (dump_ctx != NULL) {
+		kdump_free(dump_ctx);
+		dump_ctx = NULL;
+	}
+
+	kdump_gdbarch = NULL;
+}
+
+static int init_types(int);
+static int init_types(int flags)
+{
+	struct type *t, *et;
+	int i, nc, r;
+	kdump_reg_t reg;
+
+	nc = kdump_num_cpus(dump_ctx);
+	types.ncpus = kdump_num_cpus(dump_ctx);
+
+	for (i = 0; i < nc; i++) {
+		for (r = 0; ; r++) {
+			if (kdump_read_reg(dump_ctx, i, r, &reg)) break;
+#ifdef _DEBUG
+			printf_filtered("CPU % 2d,REG%02d=%llx\n", i, r, (long long unsigned int)reg);
+#endif
+		}
+	}
+
+	return kdump_types_init(flags);
+}
+
+static offset get_percpu_offset(const char *varname, int ncpu);
+static offset get_percpu_offset(const char *varname, int ncpu)
+{
+	char buff[MAXSYMNAME];
+	char b[sizeof(offset)];
+	offset off = NULL_offset;
+
+	struct bound_minimal_symbol bmsym;
+
+	snprintf(buff, sizeof(buff)-1, "%s", varname);
+
+	do {
+		off = get_symbol_value(buff);
+		if (off >= OFFSET(percpu_start) && off <= OFFSET(percpu_end)) {
+			off = off + OFFSET(percpu_offsets[ncpu]);
+			break;
+		}
+
+		bmsym = lookup_minimal_symbol(buff, NULL, NULL);
+		if (bmsym.minsym) {
+			struct obj_section *os;
+			struct objfile *of;
+			os = MSYMBOL_OBJ_SECTION(bmsym.objfile, bmsym.minsym);
+
+			if (os && os->the_bfd_section && !strcmp(os->the_bfd_section->name, ".data..percpu")) {
+				off = off + OFFSET(percpu_offsets[ncpu]);
+				break;
+			}
+		}
+
+	} while(0);
+
+	return off;
+}
+
+static void init_runqueues(void);
+static void init_runqueues(void)
+{
+	int i;
+	offset r, curr;
+	char *runq;
+
+	runq = KDUMP_TYPE_ALLOC(rq);
+
+	for(i = 0; i < types.ncpus; i++) {
+		r = get_percpu_offset("runqueues", i);
+		if (r == NULL_offset) {
+			error(_("Cannot get pcpu offset of \'runqueues\':%d\n"), i);
+			goto out;
+		}
+		if (KDUMP_TYPE_GET(rq, r, runq)) {
+			error(_("Cannot get runqueue\n"));
+			goto out;
+		}
+		curr = kt_ptr_value(runq + MEMBER_OFFSET(rq,curr));
+
+		types.cpu[i].rq.curr = curr;
+#ifdef _DEBUG
+		printf_filtered("cpu%02d->curr=%llx\n", i, curr);
+#endif
+	}
+out:
+	KDUMP_TYPE_FREE(runq);
+}
+
+/**
+ * Return the index of CPU that runs specifed task, or -1.
+ *
+ */
+static int get_process_cpu(offset task);
+static int get_process_cpu(offset task)
+{
+	int i;
+
+	for(i = 0; i < types.ncpus; i++) {
+		if (types.cpu[i].rq.curr == task) return i;
+	}
+
+	return -1;
+}
+
+static int add_task(offset off_task, int *pid_reserve, char *task);
+static int add_task(offset off_task, int *pid_reserve, char *task)
+{
+	struct symbol *s;
+	char *b = NULL, *init_task = NULL;
+	char _b[16];
+	offset rsp, rip, _rsp;
+	offset tasks;
+	offset stack;
+	offset o_init_task;
+	int state;
+	int i, cpu;
+	int hashsize;
+	struct task_info *task_info;
+
+	struct thread_info *info;
+	int pid;
+	ptid_t tt;
+	struct regcache *rc;
+	long long val;
+
+	b = _b;
+
+
+	state = kt_int_value(task + MEMBER_OFFSET(task_struct,state));
+	pid = kt_int_value(task + MEMBER_OFFSET(task_struct,pid));
+	stack = kt_ptr_value(task + MEMBER_OFFSET(task_struct,stack));
+	_rsp = rsp = kt_ptr_value(task + MEMBER_OFFSET(task_struct,thread) + MEMBER_OFFSET(thread_struct,sp));
+
+	if (pid == 0) {
+		pid = *pid_reserve;
+		*pid_reserve = pid + 1;
+	}
+	task_info = malloc(sizeof(struct task_info));
+	task_info->pid = pid;
+	task_info->cpu = -1;
+
+	if (types.arch == ARCH_S390X) {
+		if (! KDUMP_TYPE_GET(_voidp, rsp+136, b))
+			rip = kt_ptr_value(b);
+		if (KDUMP_TYPE_GET(_voidp, rsp+144, b)) return -3;
+		rsp = kt_ptr_value(b);
+		task_info->sp = rsp;
+		task_info->ip = rip;
+	} else {
+		if (KDUMP_TYPE_GET(_voidp, rsp, b)) return -2;
+		rip = kt_ptr_value(b);
+	}
+#ifdef _DEBUG
+	fprintf(stdout, "TASK %llx,%llx,rsp=%llx,rip=%llx,pid=%d,state=%d,name=%s\n", off_task, stack, rsp, rip, pid, state, task + MEMBER_OFFSET(task_struct,comm));
+#endif
+	if (pid < 0) {
+		free_task_info((struct private_thread_info*)task_info);
+		return 0;
+	}
+
+	task_info->task_struct = off_task;
+
+	tt = ptid_build (1, pid, 0);
+	info = add_thread(tt);
+	info->priv = (struct private_thread_info*)task_info;
+	info->private_dtor = free_task_info;
+
+	inferior_ptid = tt;
+	info->name = strdup(task + MEMBER_OFFSET(task_struct,comm));
+
+	val = 0;
+
+	rc = get_thread_regcache (tt);
+
+	if (types.arch == ARCH_S390X) {
+
+		if (((cpu = get_process_cpu(off_task)) != -1)) {
+#ifdef _DEBUG
+			printf("task %p is running on %d\n", (void*)task_info->task_struct, cpu);
+#endif
+		}
+		/*
+		 * TODO: implement retrieval of register values from lowcore
+		 */
+		val = be64toh(rip);
+		regcache_raw_supply(rc, 1, &val);
+
+		if (! KDUMP_TYPE_GET(_voidp, _rsp+136, b)) regcache_raw_supply(rc, S390_R14_REGNUM, b);
+		if (! KDUMP_TYPE_GET(_voidp, _rsp+128, b)) regcache_raw_supply(rc, S390_R13_REGNUM, b);
+		if (! KDUMP_TYPE_GET(_voidp, _rsp+120, b)) regcache_raw_supply(rc, S390_R12_REGNUM, b);
+		if (! KDUMP_TYPE_GET(_voidp, _rsp+112, b)) regcache_raw_supply(rc, S390_R11_REGNUM, b);
+		if (! KDUMP_TYPE_GET(_voidp, _rsp+104, b)) regcache_raw_supply(rc, S390_R10_REGNUM, b);
+		if (! KDUMP_TYPE_GET(_voidp, _rsp+96, b)) regcache_raw_supply(rc, S390_R9_REGNUM, b);
+		if (! KDUMP_TYPE_GET(_voidp, _rsp+88, b)) regcache_raw_supply(rc, S390_R8_REGNUM, b);
+		if (! KDUMP_TYPE_GET(_voidp, _rsp+80, b)) regcache_raw_supply(rc, S390_R7_REGNUM, b);
+		if (! KDUMP_TYPE_GET(_voidp, _rsp+72, b)) regcache_raw_supply(rc, S390_R6_REGNUM, b);
+		if (! KDUMP_TYPE_GET(_voidp, _rsp+64, b)) regcache_raw_supply(rc, S390_R5_REGNUM, b);
+		if (! KDUMP_TYPE_GET(_voidp, _rsp+56, b)) regcache_raw_supply(rc, S390_R4_REGNUM, b);
+		if (! KDUMP_TYPE_GET(_voidp, _rsp+48, b)) regcache_raw_supply(rc, S390_R3_REGNUM, b);
+		if (! KDUMP_TYPE_GET(_voidp, _rsp+40, b)) regcache_raw_supply(rc, S390_R2_REGNUM, b);
+		if (! KDUMP_TYPE_GET(_voidp, _rsp+32, b)) regcache_raw_supply(rc, S390_R1_REGNUM, b);
+		
+		val = be64toh(rsp);
+		regcache_raw_supply(rc, S390_R15_REGNUM, &val);
+	} else if (types.arch == ARCH_X86_64) {
+		/*
+		 * The task is not running - e.g. crash would show it's stuck in schedule()
+		 * Yet schedule() is not on its stack.
+		 *
+		 */
+		cpu = 0;
+		if (((cpu = get_process_cpu(off_task)) == -1)) {
+			long long regs[64];
+
+			/*
+			 * So we're gonna skip its stackframe
+			 * FIXME: use the size obtained from debuginfo
+			 */
+			rsp += 0x148;
+			target_read_raw_memory(rsp - 0x8 * (1 + 6), (void*)regs, 0x8 * 6);
+
+			regcache_raw_supply(rc, 15, &regs[5]);
+			regcache_raw_supply(rc, 14, &regs[4]);
+			regcache_raw_supply(rc, 13, &regs[3]);
+			regcache_raw_supply(rc, 12, &regs[2]);
+			regcache_raw_supply(rc, 6, &regs[1]);
+			regcache_raw_supply(rc, 3, &regs[0]);
+
+			KDUMP_TYPE_GET(_voidp, rsp, b);
+			rip = kt_ptr_value(b);
+			rsp += 8;
+
+			regcache_raw_supply(rc, 7, &rsp);
+			regcache_raw_supply(rc, 16, &rip);
+
+			task_info->sp = rsp;
+			task_info->ip = rip;
+		} else {
+			kdump_reg_t reg;
+
+			task_info->cpu = cpu;
+#ifdef _DEBUG
+			printf("task %p is running on %d\n", (void*)task_info->task_struct, cpu);
+#endif
+
+#define REG(en,mem) kdump_read_reg(dump_ctx, cpu, GET_REGISTER_OFFSET(mem), &reg); regcache_raw_supply(rc, en, &reg)
+		
+			REG(reg_RSP,sp);
+			task_info->sp = reg;
+			REG(reg_RIP,ip);
+			printf ("task %p cpu %02d rip = %p\n", (void*)task_info->task_struct, cpu, reg);
+			task_info->ip = reg;
+			REG(reg_RAX,ax);
+			REG(reg_RCX,cx);
+			REG(reg_RDX,dx);
+			REG(reg_RBX,bx);
+			REG(reg_RBP,bp);
+			REG(reg_RSI,si);
+			REG(reg_RDI,di);
+			REG(reg_R8,r8);
+			REG(reg_R9,r9);
+			REG(reg_R10,r10);
+			REG(reg_R11,r11);
+			REG(reg_R12,r12);
+			REG(reg_R13,r13);
+			REG(reg_R14,r14);
+			REG(reg_R15,r15);
+			REG(reg_RFLAGS,flags);
+			REG(reg_ES,es);
+			REG(reg_CS,cs);
+			REG(reg_SS,ss);
+			REG(reg_DS,ds);
+			REG(reg_FS,fs);
+			REG(reg_GS,gs);
+#undef REG
+		}
+	} else if (types.arch == ARCH_PPC64LE) {
+		if (((cpu = get_process_cpu(off_task)) == -1)) {
+			val = 789;
+			regcache_raw_supply(rc, 1, &val);
+			val = 456;
+			regcache_raw_supply(rc, 64, &val);
+			for (i = 0; i < 169; i ++) {
+				val = htobe64(i);
+				regcache_raw_supply(rc, i, &val);
+			}
+		} else {
+			kdump_reg_t reg;
+			task_info->cpu = cpu;
+			long long regs[64];
+			for (i = 0; i < 32; i ++) {
+				kdump_read_reg(dump_ctx, cpu, i, &reg);
+				val = htobe64(reg);
+				regcache_raw_supply(rc, i, &val);
+			//	kdump_read_reg(dump_ctx, cpu, 32, &reg); regcache_raw_supply(rc, 32, &val);
+			//	kdump_read_reg(dump_ctx, cpu, 1, &reg); regcache_raw_supply(rc, 1, &val);
+			}
+			for (i = 32; i < 49; i ++) {
+				kdump_read_reg(dump_ctx, cpu, i, &reg);
+				val = htobe64(reg);
+				regcache_raw_supply(rc, i+32, &val);
+			}
+			kdump_read_reg(dump_ctx, cpu, 32, &reg);
+			task_info->ip = reg;
+			kdump_read_reg(dump_ctx, cpu, 1, &reg);
+			task_info->sp = reg;
+			for (i = 0; i < 129; i ++) {
+				val = i;
+			//	regcache_raw_supply(rc, i, &val);
+			}
+		}
+	}
+
+	return 0;
+}
+
+static int init_values(void);
+static int init_values(void)
+{
+	struct symbol *s;
+	char *b = NULL, *init_task = NULL, *task = NULL;
+	offset off, off_task, rsp, rip, _rsp;
+	offset tasks;
+	offset stack;
+	offset o_init_task;
+	int state;
+	int i, cpu;
+	int hashsize;
+	struct inferior *in;
+	int cnt = 0;
+	int pid_reserve;
+	struct task_info *task_info;
+
+	s = NULL;
+	
+	b = KDUMP_TYPE_ALLOC(_voidp);
+	if (!b) goto error;
+
+	OFFSET(percpu_start) = get_symbol_value("__per_cpu_start");
+	OFFSET(percpu_end) = get_symbol_value("__per_cpu_end");
+	off = get_symbol_value("__per_cpu_offset");
+	types.cpu = malloc(sizeof(struct cpuinfo)*types.ncpus);
+	OFFSET(percpu_offsets) = malloc(sizeof(offset)*types.ncpus);
+	memset(OFFSET(percpu_offsets), 0, sizeof(offset)*types.ncpus);
+
+	for (i = 0; i < types.ncpus; i++) {
+		if (KDUMP_TYPE_GET(_voidp, off + GET_TYPE_SIZE(_voidp)*i, b)) goto error;
+		OFFSET(percpu_offsets[i]) = kt_ptr_value(b);
+#ifdef _DEBUG
+		printf ("pcpu[%d]=%llx\n", i, OFFSET(percpu_offsets[i]));
+#endif
+	}
+
+	init_runqueues();
+
+	o_init_task = get_symbol_value("init_task");
+	if (! o_init_task) {
+		warning(_("Cannot find init_task\n"));
+		return -1;
+	}
+	init_task = KDUMP_TYPE_ALLOC(task_struct);
+	if (!init_task)
+		goto error;
+	task = KDUMP_TYPE_ALLOC(task_struct);
+	if (!task) goto error;
+	if (KDUMP_TYPE_GET(task_struct, o_init_task, init_task))
+		goto error;
+	tasks = kt_ptr_value(init_task + MEMBER_OFFSET(task_struct,tasks));
+
+	i = 0;
+	off = 0;
+	pid_reserve = 50000;
+
+	print_thread_events = 0;
+	in = current_inferior();
+	inferior_appeared (in, 1);
+
+	list_head_for_each(tasks, init_task + MEMBER_OFFSET(task_struct,tasks), off) {
+		
+		struct thread_info *info;
+		int pid;
+		ptid_t tt;
+		struct regcache *rc;
+		long long val;
+		offset main_tasks, mt;
+		
+
+		//fprintf(stderr, __FILE__":%d: ok\n", __LINE__);
+		off_task = off - MEMBER_OFFSET(task_struct,tasks);
+		if (KDUMP_TYPE_GET(task_struct, off_task, task)) continue;
+
+		main_tasks = off_task;//kt_ptr_value(task + MEMBER_OFFSET(task_struct,thread_group));
+
+		do {
+		//list_head_for_each(main_tasks, task + MEMBER_OFFSET(task_struct,thread_group), mt) {
+
+			//off_task = mt - MEMBER_OFFSET(task_struct,thread_group);
+			if (KDUMP_TYPE_GET(task_struct, off_task, task))  {
+				continue;
+			}
+
+			if (add_task(off_task, &pid_reserve, task)) {
+
+			} else {
+				
+				printf_unfiltered(_("Loaded processes: %d\r"), ++cnt);
+			}
+			off_task = kt_ptr_value(task + MEMBER_OFFSET(task_struct, thread_group)) - MEMBER_OFFSET(task_struct, thread_group);
+			if (off_task == main_tasks) break;
+
+		} while (1);
+	}
+
+	if (b) free(b);
+	if (init_task) free(init_task);
+
+	printf_unfiltered(_("Loaded processes: %d\n"), cnt);
+	return 0;
+error:
+	if (b) free(b);
+	if (init_task) free(init_task);
+
+	return 1;
+}
+
+struct t_kdump_arch {
+	char *kdident;
+	char *gdbident;
+	int flags;
+	t_arch arch;
+	int (*init_func)(const struct t_kdump_arch *, int *);
+} ;
+
+static int kdump_ppc64_init(const struct t_kdump_arch *a, int *flags)
+{
+	*flags = F_BIG_ENDIAN;
+	return 0;
+}
+
+static const struct t_kdump_arch archlist[] = {
+	{"x86_64", "i386:x86-64",      F_LITTLE_ENDIAN, ARCH_X86_64,  NULL},
+	{"s390x",  "s390:64-bit",      F_BIG_ENDIAN,    ARCH_S390X,   NULL},
+	{"ppc64",  "powerpc:common64", F_UNKN_ENDIAN,   ARCH_PPC64LE, kdump_ppc64_init},
+	{NULL}
+};
+
+
+static int kdump_do_init(void);
+static int kdump_do_init(void)
+{
+	const bfd_arch_info_type *ait;
+	struct gdbarch_info gai;
+	struct gdbarch *garch;
+	struct inferior *inf;
+	const char *archname;
+	const struct t_kdump_arch *a;
+	int flags, ret;
+	ptid_t tt;
+
+	archname = kdump_arch_name(dump_ctx);
+	if (! archname) {
+		error(_("The architecture could not be identified"));
+		return -1;
+	}
+	for (a = archlist; a->kdident && strcmp(a->kdident, archname); a++);
+
+	if (! a->kdident) {
+		error(_("Architecture %s is not yet supported by gdb-kdump\n"), archname);
+		return -2;
+	}
+
+	gdbarch_info_init(&gai);
+	ait = bfd_scan_arch (a->gdbident);
+	if (! ait) {
+		error(_("Architecture %s not supported in gdb\n"), a->gdbident);
+		return -3;
+	}
+	gai.bfd_arch_info = ait;
+	garch = gdbarch_find_by_info(gai);
+	kdump_gdbarch = garch;
+#ifdef _DEBUG
+	fprintf(stderr, "arch=%s,ait=%p,garch=%p\n", selected_architecture_name(), ait, garch);
+#endif
+	flags = a->flags;
+	if (a->init_func) {
+		if ((ret = a->init_func(a, &flags)) != 0) {
+			error(_("Architecture %s init_func()=%d"), a->kdident, ret);
+			return -5;
+		}
+	}
+	init_thread_list();
+	inf = current_inferior();
+
+	types.arch = a->arch;
+	
+	if (init_types(flags)) {
+		warning(_("kdump: Cannot init types!\n"));
+	}
+	if (init_values()) {
+		warning(_("kdump: Cannot init values!\n"));
+	}
+	set_executing(minus_one_ptid,0);
+	reinit_frame_cache();
+
+	return 0;
+}
+
+static kdump_status kdump_get_symbol_val_cb(kdump_ctx *ctx, const char *name, kdump_addr_t *val)
+{
+	*val = (kdump_addr_t) get_symbol_address(name);
+	return kdump_ok;
+}
+
+static void
+kdump_open (const char *arg, int from_tty)
+{
+	const char *p;
+	int siggy;
+	struct cleanup *old_chain;
+	char *temp;
+	bfd *temp_bfd;
+	int scratch_chan;
+	int flags;
+	volatile struct gdb_exception except;
+	char *filename;
+	int fd;
+
+	target_preopen (from_tty);
+	if (!arg) {
+		if (core_bfd)
+			error (_("No kdump file specified.  (Use `detach' "
+				"to stop debugging a core file.)"));
+		else
+			error (_("No kdump file specified."));
+	}
+
+	filename = tilde_expand (arg);
+	if (!IS_ABSOLUTE_PATH (filename))
+	{
+		temp = concat (current_directory, "/", filename, (char *) NULL);
+		xfree (filename);
+		filename = temp;
+	}
+	if ((fd = open(filename, O_RDONLY)) == -1) {
+		error(_("\"%s\" cannot be opened: %s\n"), filename, strerror(errno));
+		return;
+	}
+
+	dump_ctx = kdump_init();
+	if (!dump_ctx) {
+		error(_("kdump_init() failed, \"%s\" cannot be opened as kdump\n"), filename);
+		return;
+	}
+
+	kdump_cb_get_symbol_val(dump_ctx, kdump_get_symbol_val_cb);
+
+	if (kdump_set_fd(dump_ctx, fd) != kdump_ok) {
+		error(_("\"%s\" cannot be opened as kdump\n"), filename);
+		return;
+	}
+
+	if (kdump_vtop_init(dump_ctx) != kdump_ok) {
+		error(_("Cannot kdump_vtop_init(%s)\n"), kdump_err_str(dump_ctx));
+		return;
+	}
+
+	old_chain = make_cleanup (xfree, filename);
+
+	flags = O_BINARY | O_LARGEFILE;
+	if (write_files)
+		flags |= O_RDWR;
+	else
+		flags |= O_RDONLY;
+	scratch_chan = gdb_open_cloexec (filename, flags, 0);
+	if (scratch_chan < 0)
+		perror_with_name (filename);
+
+	push_target (&core_ops);
+	
+	if (kdump_do_init()) {
+		error(_("Cannot initialize kdump"));
+	}
+
+	return;
+}
+
+static void
+core_detach (struct target_ops *ops, const char *args, int from_tty)
+{
+	if (args)
+		error (_("Too many arguments"));
+	unpush_target (ops);
+	reinit_frame_cache ();
+	if (from_tty)
+		printf_filtered (_("No core file now.\n"));
+}
+
+static kdump_paddr_t transform_memory(kdump_paddr_t addr);
+static kdump_paddr_t transform_memory(kdump_paddr_t addr)
+{
+	kdump_paddr_t out;
+	if (kdump_ok == kdump_vtop(dump_ctx, addr, &out)) return out;
+	return addr;
+}
+
+static enum target_xfer_status
+kdump_xfer_partial (struct target_ops *ops, enum target_object object,
+			 const char *annex, gdb_byte *readbuf,
+			 const gdb_byte *writebuf, ULONGEST offset,
+			 ULONGEST len, ULONGEST *xfered_len)
+{
+	ULONGEST i;
+	size_t r;
+	if (dump_ctx == NULL) {
+		error(_("dump_ctx == NULL\n"));
+	}
+	switch (object)
+	{
+		case TARGET_OBJECT_MEMORY:
+			offset = transform_memory((kdump_paddr_t)offset);
+			r = kdump_read(dump_ctx, (kdump_paddr_t)offset, (unsigned char*)readbuf, (size_t)len, KDUMP_PHYSADDR);
+			if (r != len) {
+				error(_("Cannot read %lu bytes from %lx (%lld)!"), (size_t)len, (long unsigned int)offset, (long long)r);
+			} else
+				*xfered_len = len;
+
+			return TARGET_XFER_OK;
+
+		default:
+			return ops->beneath->to_xfer_partial (ops->beneath, object,
+				annex, readbuf,
+				writebuf, offset, len,
+				xfered_len);
+	}
+}
+
+static int ignore (struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
+{
+	return 0;
+}
+
+static int
+core_thread_alive (struct target_ops *ops, ptid_t ptid)
+{
+	return 1;
+}
+
+static const struct target_desc *
+core_read_description (struct target_ops *target)
+{
+	if (kdump_gdbarch && gdbarch_core_read_description_p (kdump_gdbarch))
+	{
+		const struct target_desc *result;
+
+		result = gdbarch_core_read_description (kdump_gdbarch, target, core_bfd);
+		if (result != NULL) return result;
+	}
+
+	return target->beneath->to_read_description (target->beneath);
+}
+
+static int core_has_memory (struct target_ops *ops)
+{
+	return 1;
+}
+
+static int core_has_stack (struct target_ops *ops)
+{
+	return 1;
+}
+
+static int core_has_registers (struct target_ops *ops)
+{
+	return 1;
+}
+
+#ifdef _DEBUG
+void kdumptest_file_command (char *filename, int from_tty);
+void kdumptest_file_command (char *filename, int from_tty)
+{
+	const char *sname = "default_llseek";
+	struct symbol *ss;
+	const struct language_defn *lang;
+	struct value *val;
+	struct objfile *obj;
+	struct symtab_and_line sal;
+	CORE_ADDR addr;
+	ss = lookup_global_symbol(sname, NULL, FUNCTIONS_DOMAIN);
+	if (! ss) {
+		return;
+	}
+	lang  = language_def (SYMBOL_LANGUAGE (ss));
+	val = lang->la_read_var_value (ss, NULL);
+	if (! val) {
+		return;
+	}
+	addr = value_address(val);
+	printf("symbol = %llx\n", (unsigned long long)addr);
+
+	ss = lookup_static_symbol("modules", VAR_DOMAIN);
+	printf("MOD:symbol = %llx\n", (unsigned long long)ss);
+
+	sal = find_pc_line (addr, 0);
+	if (sal.line) {
+		if (sal.objfile) {
+			if (sal.objfile->original_name)
+				printf("original name = %s\n", sal.objfile->original_name);
+			printf("sal.objfile=%p\n", sal.objfile);
+		}
+		if (sal.section) {
+			if (sal.section->objfile) {
+				if (sal.section->objfile->original_name)
+					printf("original name = %s\n", sal.section->objfile->original_name);
+				printf("sal.section->objfile=%p\n", sal.section->objfile);
+			} else {
+				if (sal.section->the_bfd_section) {
+					printf("bfd_section\n");
+				} else
+					printf("nothing\n");
+			}
+		} else {
+			printf("no section\n");
+		}
+		if (sal.symtab && sal.symtab->filename) {
+			printf("symtab->filename=%s\n", sal.symtab->filename);
+		}
+
+		printf ("line=%d,pc=%llx,end=%llx\n", sal.line, (offset)sal.pc, (offset)sal.end);
+	}
+	{
+		struct symbol *ss;
+		const struct language_defn *lang;
+		struct value *val;
+		struct obj_section *os;
+		ss = lookup_global_symbol("runqueues", NULL, VAR_DOMAIN);
+		if (! ss) {
+			return;
+		}
+		printf("sect %d\n", SYMBOL_SECTION(ss));
+		//os = SYMBOL_OBJ_SECTION(ss);
+		if (ss->is_objfile_owned) {
+			printf("symtab=%p\n", ss->owner.symtab);
+			if (ss->owner.symtab->compunit_symtab) {
+				printf ("objfile %p\n", ss->owner.symtab->compunit_symtab->objfile);
+				os = SYMBOL_OBJ_SECTION(ss->owner.symtab->compunit_symtab->objfile, ss);
+				if (os->the_bfd_section) {
+					printf("bfd yes! \'%s\'\n", os->the_bfd_section->name);
+				}
+			}
+		}
+	}
+
+	printf ("percpu(runqueues,1)=%llx\n", get_percpu_offset("runqueues",1));
+
+	printf("sp_regnum=%d\n", gdbarch_sp_regnum(kdump_gdbarch));
+	if (gdbarch_unwind_sp_p (kdump_gdbarch))
+		printf("gdbarch_unwind_sp_p=TRUE\n");
+
+	fflush(stdout);
+	printf("PG_slab=%llx\n", get_symbol_value("PG_slab"));
+	return;
+}
+#endif
+
+void kdump_file_command (char *filename, int from_tty);
+void kdump_file_command (char *filename, int from_tty)
+{
+	dont_repeat ();
+
+	gdb_assert (kdump_target != NULL);
+
+	if (!filename)
+		(kdump_target->to_detach) (kdump_target, filename, from_tty);
+	else
+		(kdump_target->to_open) (filename, from_tty);
+}
+
+/**
+ * The following code is meant to just search the given path
+ * for the modules debuginfo files.
+ */
+struct t_directory {
+	char *name;
+	struct t_directory *parent;
+	struct t_directory *next;
+	struct t_directory *_next;
+};
+
+struct t_node {
+	char *filename;
+	struct t_node *lt;
+	struct t_node *gt;
+	struct t_directory *parent;
+	struct t_node *_next;
+};
+
+static struct t_node *rootnode;
+static struct t_directory rootdir;
+static char rootname[NAME_MAX];
+static struct t_node *nodelist;
+
+static void putname(char *path, struct t_directory *dir)
+{
+	char *v, *c = path;
+	for (v = path; dir; dir = dir->parent) {
+		const char *e = dir->name + strlen(dir->name) - 1;
+		*v++ = '/';
+		while (e >= dir->name)
+			*v++ = *e--;
+	}
+	*v-- = '\0';
+	while (v > path) {
+		char z = *v;
+		*v = *path;
+		*path = z;
+		v --;
+		path ++;
+	}
+}
+
+static void insertnode(struct t_node *node, struct t_node **where)
+{
+	while(* where) {
+		int ret = strcmp(node->filename, (*where)->filename);
+		if (ret < 0) where = & (*where)->lt;
+		else if (ret > 0) where = & (*where)->gt;
+		else break;
+	}
+	* where = node;
+	return;
+}
+
+/**
+ * Finds the file of the given name (only the files', not full path).
+ * If found, it puts its full path in output and returns !NULL .
+ * If not found, it returns NULL.
+ */
+static const char *find_module(const char *name, char *output)
+{
+	struct t_node *nod = rootnode;
+	int ret;
+
+	while(nod && (ret = strcmp(nod->filename, name)) != 0) {
+		if (ret > 0) nod = nod->lt;
+		else if (ret < 0) nod = nod->gt;
+	}
+	if (! nod) return NULL;
+	putname(output, nod->parent);
+	strcat(output, nod->filename);
+	return output;
+}
+
+static void free_module_list(void)
+{
+	struct t_directory *n, *p;
+	struct t_node *no, *po;
+	
+	for (n = rootdir._next; ; n = p) {
+		if (!n) break;
+		p = n->_next;
+		if (n->name) free (n->name);
+		free (n);
+	}
+
+	for (no = nodelist; ; no = po) {
+		if (!no) break;
+		po = no->_next;
+		if (no->filename) free (no->filename);
+		free (no);
+	}
+
+	rootdir._next = NULL;
+	nodelist = NULL;
+}
+
+/**
+ * Init the list of modules - walk through p_path and remember
+ * all the regular files with names ending on p_suffix.
+ */
+static void init_module_list(const char *p_path, const char *p_suffix)
+{
+	char path[NAME_MAX];
+	struct t_directory *di;
+	int suffixlen;
+	DIR *d;
+
+	suffixlen = strlen(p_suffix);
+	rootnode = NULL;
+	nodelist = NULL;
+	di = &rootdir;
+	snprintf(rootname, sizeof(rootname)-1, "%s", p_path);
+	rootdir.name = rootname;
+	rootdir.parent = NULL;
+	rootdir.next = NULL;
+
+	while(di) {
+		struct dirent en, *_en;
+		putname(path, di);
+		d = opendir(path);
+		if (!d) {
+			error(_("Cannot open dir %s!\n"), path);
+			return;
+		}
+		while (! readdir_r(d, &en, &_en) && (_en)) {
+			int type;
+
+			type = en.d_type;
+
+			if (en.d_name[0] == '.') continue;
+			if (type == DT_UNKNOWN) {
+				char npath[NAME_MAX];
+				struct stat st;
+				snprintf(npath, sizeof(npath)-1, "%s/%s", path, en.d_name);
+				if (stat(npath, &st) == 0) {
+					if (S_ISDIR(st.st_mode)) type = DT_DIR;
+					else if (S_ISREG(st.st_mode)) type = DT_REG;
+				}
+			}
+
+			if (type == DT_DIR) {
+				struct t_directory *ndi = malloc(sizeof(struct t_directory));
+				ndi->_next = rootdir._next;
+				rootdir._next = ndi;
+				ndi->next = di->next;
+				ndi->name = strdup(en.d_name);
+				ndi->parent = di;
+				di->next = ndi;
+			} else if (type == DT_REG) {
+				int l = strlen(en.d_name);
+
+				if (l > suffixlen && !strcmp(en.d_name+l-suffixlen, p_suffix)) {
+					struct t_node *nod = malloc(sizeof(struct t_node));
+					nod->_next = nodelist;
+					nodelist = nod;
+					nod->filename = strdup(en.d_name);
+					nod->parent = di;
+					nod->lt = nod->gt = NULL;
+					insertnode(nod, &rootnode);
+				}
+			}
+		}
+		closedir(d);
+		di = di->next;
+	}
+}
+
+static void kdumpmodules_command (char *filename, int from_tty);
+static void kdumpmodules_command (char *filename, int from_tty)
+{
+	offset sym_modules, modules, mod, off_mod, addr;
+	char *module = NULL;
+	char *v = NULL;
+	char modulename[56+9+1];
+	char modulepath[NAME_MAX];
+	int flags = OBJF_USERLOADED | OBJF_SHARED;
+	struct section_addr_info *section_addrs;
+	struct objfile *objf;
+
+	if (dump_ctx == NULL) {
+		error(_("dump_ctx == NULL\n"));
+	}
+	if (! filename || ! strlen(filename)) {
+		error(_("Specify name of directory to load the modules debuginfo from"));
+	}
+	section_addrs = alloc_section_addr_info (1);
+	section_addrs->other[0].name = ".text";
+
+	/* search the path for modules */
+	init_module_list(filename, ".ko.debug");
+	module = KDUMP_TYPE_ALLOC(module);
+	v = KDUMP_TYPE_ALLOC(_voidp);
+	sym_modules = get_symbol_value("modules");
+	if(KDUMP_TYPE_GET(_voidp, sym_modules, v)) goto error;
+	modules = kt_ptr_value(v);
+
+	/* now walk through the module list (of the dumped kernel) and for each module
+	 * try to find it's debuginfo file */
+	list_head_for_each(modules, v, mod) {
+		if (mod == sym_modules) break;
+		off_mod = mod - MEMBER_OFFSET(module,list);
+		if(KDUMP_TYPE_GET(module, off_mod, module)) goto error;
+		snprintf(modulename, sizeof(modulename)-1, "%s.ko.debug", module + MEMBER_OFFSET(module,name));
+		if (! find_module(modulename, modulepath)) {
+			warning(_("Cannot find debuginfo file for module \"%s\""), modulename);
+			continue;
+		}
+		addr = kt_ptr_value(module + MEMBER_OFFSET(module,module_core));
+#ifdef _DEBUG
+		fprintf(stderr, "Going to load module %s at %llx\n", modulepath, addr);
+#endif
+		section_addrs->other[0].addr = addr;
+		section_addrs->num_sections = 1;
+
+		/* load the module' debuginfo (at its module_core address) */
+		objf = symbol_file_add (modulepath, from_tty ? SYMFILE_VERBOSE : 0,
+				  section_addrs, flags);
+		add_target_sections_of_objfile (objf);
+	}
+	
+	error:
+
+	if (v) free(v);
+	if (module) free(module);
+	free_module_list();
+}
+
+static void kdumpps_command(char *fn, int from_tty);
+static void kdumpps_command(char *fn, int from_tty)
+{
+	struct thread_info *tp;
+	struct task_info *task;
+	char cpu[6];
+
+	if (dump_ctx == NULL) {
+		error(_("dump_ctx == NULL\n"));
+	}
+	for (tp = thread_list; tp; tp = tp->next) {
+		task = (struct task_info*)tp->priv;
+		if (!task) continue;
+		if (task->cpu == -1) cpu[0] = '\0';
+		else snprintf(cpu, 5, "% 4d", task->cpu);
+		printf_filtered(_("% 7d %llx %llx %llx %-4s %s\n"), task->pid, task->task_struct, task->ip, task->sp, cpu, tp->name);
+	}
+}
+
+static char *
+kdump_pid_to_str (struct target_ops *ops, ptid_t ptid)
+{
+	static char buf[32];
+	xsnprintf (buf, sizeof buf, "pid %ld", ptid_get_lwp (ptid));
+	return buf;
+}
+
+struct cmd_list_element *kdumplist = NULL;
+static void init_core_ops (void)
+{
+	struct cmd_list_element *c;
+	core_ops.to_shortname = "kdump";
+	core_ops.to_longname = "Compressed kdump file";
+	core_ops.to_doc =
+		"Use a vmcore file as a target.  Specify the filename of the vmcore file.";
+	core_ops.to_open = kdump_open;
+	core_ops.to_close = core_close;
+	core_ops.to_detach = core_detach;
+	core_ops.to_xfer_partial = kdump_xfer_partial;
+	core_ops.to_insert_breakpoint = ignore;
+	core_ops.to_remove_breakpoint = ignore;
+	core_ops.to_thread_alive = core_thread_alive;
+	core_ops.to_read_description = core_read_description;
+	core_ops.to_stratum = process_stratum;
+	core_ops.to_has_memory = core_has_memory;
+	core_ops.to_has_stack = core_has_stack;
+	core_ops.to_has_registers = core_has_registers;
+	core_ops.to_magic = OPS_MAGIC;
+	core_ops.to_pid_to_str = kdump_pid_to_str;
+
+	if (kdump_target)
+		internal_error (__FILE__, __LINE__,
+			_("init_kdump_ops: core target already exists (\"%s\")."),
+			kdump_target->to_longname);
+
+	kdump_target = &core_ops;
+
+	c = add_prefix_cmd ("kdump", no_class, kdumpmodules_command,
+		_("Commands for ease work with kernel dump target"),
+		&kdumplist, "kdump ", 0, &cmdlist);
+
+	c = add_cmd ("modules", class_files, kdumpmodules_command,
+		_("Load modules debuginfo from directory"), &kdumplist);
+	set_cmd_completer (c, filename_completer);
+
+	c = add_cmd ("ps", class_files, kdumpps_command,
+		_("Print ps info"), &kdumplist);
+
+	set_cmd_completer (c, filename_completer);
+
+#ifdef _DEBUG
+	c = add_cmd ("kdumptest", class_files, kdumptest_file_command, _("\
+Test command"), &kdumplist);
+#endif
+}
+
+void
+_initialize_kdump (void)
+{
+	init_core_ops ();
+
+	add_target_with_completer (&core_ops, filename_completer);
+}
diff --git a/gdb/mi/mi-out.c b/gdb/mi/mi-out.c
index 20f59c3..e9693aa 100644
--- a/gdb/mi/mi-out.c
+++ b/gdb/mi/mi-out.c
@@ -166,7 +166,6 @@ mi_begin (struct ui_out *uiout, enum ui_out_type type, int level,
 
   if (data->suppress_output)
     return;
-
   mi_open (uiout, id, type);
 }
 
@@ -403,7 +402,7 @@ mi_out_new (int mi_version)
   int flags = 0;
 
   mi_out_data *data = XNEW (mi_out_data);
-  data->suppress_field_separator = 0;
+  data->suppress_field_separator = 1;
   data->suppress_output = 0;
   data->mi_version = mi_version;
   /* FIXME: This code should be using a ``string_file'' and not the
diff --git a/gdb/python/lib/gdb/kdump/__init__.py b/gdb/python/lib/gdb/kdump/__init__.py
new file mode 100644
index 0000000..f9cfe7b
--- /dev/null
+++ b/gdb/python/lib/gdb/kdump/__init__.py
@@ -0,0 +1,20 @@
+import gdb
+
+def list_head(obj, field, typ=None):
+	if typ == None:
+		typ = obj.type
+	nextaddr = long(obj[field.name]["next"])
+	addr = long(long(obj.address)+(field.bitpos>>3))
+	
+	yield obj
+
+	while not addr == nextaddr:
+		nv = gdb.Value(long(nextaddr-(field.bitpos>>3))).cast(typ.pointer()).dereference()
+		nextaddr = long(nv[field.name]["next"])
+		yield nv
+
+		"""
+import gdb.kdump
+sz=gdb.lookup_symbol("init_task")[0]
+g=gdb.kdump.list_head(sz.value(), sz.value().type["tasks"])
+"""
diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
index 6c0f5cb..5ae44d6 100644
--- a/gdb/python/py-block.c
+++ b/gdb/python/py-block.c
@@ -103,6 +103,106 @@ blpy_iter (PyObject *self)
   return (PyObject *) block_iter_obj;
 }
 
+
+typedef struct {
+	PyObject_HEAD
+	struct dict_iterator iter;
+	int finished;
+	void *value;
+	PyObject *(*func)(void *);
+} DictIter;
+
+PyObject* DictIter_iter(PyObject *self);
+PyObject* DictIter_iter(PyObject *self)
+{
+  Py_INCREF(self);
+  return self;
+}
+
+static PyObject *obj_to_sym(void *val)
+{
+  PyObject *v = symbol_to_symbol_object ((struct symbol*)val);
+  return v;
+}
+
+PyObject* DictIter_iternext(PyObject *self);
+PyObject* DictIter_iternext(PyObject *self)
+{
+  DictIter *p = (DictIter *)self;
+  PyObject *v;
+  void *n;
+
+  if (p->finished == 1)
+    return NULL;
+
+  v = p->func((struct symbol*)p->value);
+
+  n = dict_iterator_next(&p->iter);
+
+  if (!n)
+    p->finished = 1;
+  else p->value = n;
+
+  return v;
+}
+
+static PyTypeObject DictIterType = {
+PyObject_HEAD_INIT(NULL)
+0,                         /*ob_size*/
+"gdb._DictIter",            /*tp_name*/
+sizeof(DictIter),       /*tp_basicsize*/
+0,                         /*tp_itemsize*/
+0,                         /*tp_dealloc*/
+0,                         /*tp_print*/
+0,                         /*tp_getattr*/
+0,                         /*tp_setattr*/
+0,                         /*tp_compare*/
+0,                         /*tp_repr*/
+0,                         /*tp_as_number*/
+0,                         /*tp_as_sequence*/
+0,                         /*tp_as_mapping*/
+0,                         /*tp_hash */
+0,                         /*tp_call*/
+0,                         /*tp_str*/
+0,                         /*tp_getattro*/
+0,                         /*tp_setattro*/
+0,                         /*tp_as_buffer*/
+Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,
+"gdb dictionary iterator object.",           /* tp_doc */
+0,  /* tp_traverse */
+0,  /* tp_clear */
+0,  /* tp_richcompare */
+0,  /* tp_weaklistoffset */
+DictIter_iter,  /* tp_iter: __iter__() method */
+DictIter_iternext  /* tp_iternext: next() method */,
+.tp_new = PyType_GenericNew
+};                                                                                                                                                                 
+
+static PyObject *
+blpy_get_symbols(PyObject *self, void *closure)
+{
+  PyObject *tmp;
+  const struct block *block = NULL;
+  struct symbol *s;
+
+  BLPY_REQUIRE_VALID (self, block);
+
+  tmp = (PyObject*)PyObject_New(DictIter, &DictIterType);
+  if (!tmp) return NULL;
+
+  if (!PyObject_Init((PyObject *)tmp, &DictIterType)) {
+    Py_DECREF(tmp);
+    return NULL;
+  }
+
+  s = dict_iterator_first(block->dict, &((DictIter*)tmp)->iter);
+
+  ((DictIter*)tmp)->value = s;
+  ((DictIter*)tmp)->func = obj_to_sym;
+
+  return tmp;
+}
+
 static PyObject *
 blpy_get_start (PyObject *self, void *closure)
 {
@@ -437,6 +537,7 @@ gdbpy_initialize_blocks (void)
   if (PyType_Ready (&block_syms_iterator_object_type) < 0)
     return -1;
 
+  if (PyType_Ready(&DictIterType) < 0)  return -1;
   /* Register an objfile "free" callback so we can properly
      invalidate blocks when an object file is about to be
      deleted.  */
@@ -461,6 +562,7 @@ Return true if this block is valid, false if not." },
 };
 
 static PyGetSetDef block_object_getset[] = {
+  { "symbols", blpy_get_symbols, NULL, "Get symbols", NULL },
   { "start", blpy_get_start, NULL, "Start address of the block.", NULL },
   { "end", blpy_get_end, NULL, "End address of the block.", NULL },
   { "function", blpy_get_function, NULL,
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index 5a97ace..323deaf 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -52,7 +52,8 @@ const struct type_print_options type_print_raw_options =
   1,				/* print_typedefs */
   NULL,				/* local_typedefs */
   NULL,				/* global_table */
-  NULL				/* global_printers */
+  NULL,				/* global_printers */
+  0				/* print_offsets */
 };
 
 /* The default flags for 'ptype' and 'whatis'.  */
@@ -64,7 +65,8 @@ static struct type_print_options default_ptype_flags =
   1,				/* print_typedefs */
   NULL,				/* local_typedefs */
   NULL,				/* global_table */
-  NULL				/* global_printers */
+  NULL				/* global_printers */,
+  0				/* print_offsets */
 };
 
 
@@ -436,6 +438,9 @@ whatis_exp (char *exp, int show)
 		case 'T':
 		  flags.print_typedefs = 1;
 		  break;
+		case 'o':
+		  flags.print_offsets = 1;
+		  break;
 		default:
 		  error (_("unrecognized flag '%c'"), *exp);
 		}
diff --git a/gdb/typeprint.h b/gdb/typeprint.h
index bdff41b..36f5c11 100644
--- a/gdb/typeprint.h
+++ b/gdb/typeprint.h
@@ -46,6 +46,8 @@ struct type_print_options
   /* The list of type printers associated with the global typedef
      table.  This is intentionally opaque.  */
   struct ext_lang_type_printers *global_printers;
+
+  unsigned int print_offsets;
 };
 
 extern const struct type_print_options type_print_raw_options;
-- 
2.7.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]