aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrhaas <rhaas@83718e91-0e4f-0410-abf4-91180603181f>2013-03-11 21:17:31 +0000
committerrhaas <rhaas@83718e91-0e4f-0410-abf4-91180603181f>2013-03-11 21:17:31 +0000
commit940997fbf78604d45df03f8147734a97de883c9c (patch)
treefc41247f0e172aa6a46786f92609a4534ade562b
parent0f4e25f4c7d7d947b106a740ed06dfb8c7c46798 (diff)
add off-line tarball extraction utility
This patch contains python script for gdb allows one to extract the source tarballs from a formaline enabled executable, even if one is unable to runs the code anymore. Usage is: gdb -P formaline.py exe/cactus_sim which will dump the tarballs in the current directory git-svn-id: http://svn.cactuscode.org/arrangements/CactusUtils/Formaline/trunk@230 83718e91-0e4f-0410-abf4-91180603181f
-rw-r--r--doc/documentation.tex18
-rw-r--r--src/util/formaline.py52
2 files changed, 70 insertions, 0 deletions
diff --git a/doc/documentation.tex b/doc/documentation.tex
index 8e0e262..68a410c 100644
--- a/doc/documentation.tex
+++ b/doc/documentation.tex
@@ -106,6 +106,24 @@
the executable's source code into the output directory.
\end{abstract}
+\section{Utility Programs provided by Formaline}
+%
+\label{Formaline_utility_programs}
+
+Thorn Formaline provides the following utility programs:
+%
+\begin{itemize}
+ \item {\tt formaline.py}\\
+ A python script for gdb which allows you to recover the source tarballs
+ from the executable even if the executable can no longer be run. It
+ writes the extracted tarballs into the current directory. Use as
+\begin{verbatim}
+ gdb -P formaline.py exe/cactus_sim
+\end{verbatim}
+\end{itemize}
+
+All utility programs are located in src/util.
+
%% % The following sections are suggestive only.
%% % Remove them or add your own.
%%
diff --git a/src/util/formaline.py b/src/util/formaline.py
new file mode 100644
index 0000000..6656615
--- /dev/null
+++ b/src/util/formaline.py
@@ -0,0 +1,52 @@
+# gdb extension script to extract formaline tarballs from Cactus executable
+# Copyright (C) 2013 Roland Haas
+#
+# 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/>.
+#
+import io
+import sys
+
+# for some reason gdb passes an empty string in argv[0] if no argument is given
+if(not sys.argv[0]):
+ raise ValueError("needexactly one argument: gdb -P formaline.py exe/cactus_sim")
+
+# open executable and get handle to FOrmalin'e top-level source object
+gdb.execute("file %s" % sys.argv[0])
+inferior = gdb.inferiors()[0]
+cactus_source = gdb.parse_and_eval("cactus_source")
+
+# replicate logic from output_source.c
+# struct datainfo {
+# unsigned char const *data;
+# size_t length;
+# struct datainfo const *next;
+# };
+#
+# struct sourceinfo {
+# struct datainfo const *first;
+# char const *arrangement;
+# char const *thorn;
+# };
+count = 0
+while(cactus_source[count] != 0):
+ sourceinfo = cactus_source[count].dereference()
+ fn = "Cactus-source-%s.tar.gz" % sourceinfo['thorn'].string()
+ fh = io.open(fn, mode='wb')
+ datainfo = sourceinfo['first']
+ while(datainfo != 0):
+ data = inferior.read_memory(datainfo['data'], datainfo['length'])
+ fh.write(data)
+ datainfo = datainfo['next']
+ fh.close()
+ count += 1