Hi,
In my talk at pdweek, I mentioned that I had a patch to add a new
interface, BPatch_object. I've attached that patch, and I would
appreciate your comments.
My motivation is that for systemtap, we already do a lot of our own
analysis, and by the time we get to dyninst I basically have a list of
which files we'd like to probe (both executables and shared objects) and
the offsets within. So at runtime, we need to know which files are
mapped where to determine the actual addresses.
The BPatch_module interface is close, but not quite what I'm looking
for. It seems to give a view more like CUs (compilation unit).
However, I found that the internal mapped_object type has exactly the
information I'm looking for. Thus the BPatch_object interface I added
is basically just a wrapper around mapped_object.
Feedback is welcome, both on the concept and implementation.
Thanks,
Josh
PS - For the new files, I just assigned copyright to Red Hat for now,
though I realize most of Dyninst is (c) Barton P. Miller. If you can
please clarify your policy for contributions, including copyright
assignment if necessary, then I can run that by internally and
adjust as needed.
commit b07136ffb8f8bef6ece29b72a05fde43f34685ea
Author: Josh Stone <jistone@xxxxxxxxxx>
Date: Fri Apr 13 16:12:40 2012 -0700
Prototype BPatch_object, wrapping mapped_object
diff --git a/dyninstAPI/h/BPatch_image.h b/dyninstAPI/h/BPatch_image.h
index 724250d..d6ab837 100644
--- a/dyninstAPI/h/BPatch_image.h
+++ b/dyninstAPI/h/BPatch_image.h
@@ -39,6 +39,7 @@
#include "BPatch_point.h"
#include "BPatch_snippet.h"
#include "BPatch_module.h"
+#include "BPatch_object.h"
#include "BPatch_type.h"
#include "BPatch_eventLock.h"
#include "BPatch_process.h"
@@ -155,6 +156,12 @@ class BPATCH_DLL_EXPORT BPatch_image: public BPatch_sourceObj, public BPatch_eve
BPatch_Vector<BPatch_parRegion *> *,
getParRegions,(bool incUninstrumentable = false));
+ // BPatch_image::getObjects
+ //
+ // Returns a vector of all objects in this image
+ API_EXPORT(Int, (objs),
+ bool,getObjects,(BPatch_Vector<BPatch_object*> &objs));
+
// BPatch_image::getModules
//
// Returns a vector of all modules in this image
diff --git a/dyninstAPI/h/BPatch_object.h b/dyninstAPI/h/BPatch_object.h
new file mode 100644
index 0000000..f712d6f
--- /dev/null
+++ b/dyninstAPI/h/BPatch_object.h
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2012 Red Hat Inc.
+ *
+ * We provide the Paradyn Parallel Performance Tools (below
+ * described as "Paradyn") on an AS IS basis, and do not warrant its
+ * validity or performance. We reserve the right to update, modify,
+ * or discontinue this software at any time. We shall have no
+ * obligation to supply such updates or modifications or any other
+ * form of support to you.
+ *
+ * By your use of Paradyn, you understand and agree that we (or any
+ * other person or entity with proprietary rights in Paradyn) are
+ * under no obligation to provide either maintenance services,
+ * update services, notices of latent defects, or correction of
+ * defects for Paradyn.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _BPatch_object_h_
+#define _BPatch_object_h_
+
+#include "BPatch_eventLock.h"
+#include "dyntypes.h"
+
+class mapped_object;
+
+class BPatch_image;
+
+#ifdef DYNINST_CLASS_NAME
+#undef DYNINST_CLASS_NAME
+#endif
+#define DYNINST_CLASS_NAME BPatch_object
+
+class BPATCH_DLL_EXPORT BPatch_object: public BPatch_eventLock{
+
+ friend class BPatch_image;
+
+ mapped_object *obj;
+
+ BPatch_object(mapped_object* obj);
+
+public:
+
+ // BPatch_object::getFileName
+ // Returns file name associated with object
+ API_EXPORT(Int, (buffer, length),
+
+ char *,getFileName,(char *buffer, int length));
+
+ // BPatch_object::getFullName
+ // Returns full path name of object, when available
+ API_EXPORT(Int, (buffer, length),
+
+ char *,getFullName,(char *buffer, int length));
+
+ // BPatch_object::codeAbs
+ // Returns the starting address of the object
+ API_EXPORT(Int, (),
+
+ Dyninst::Address,codeAbs,());
+
+ // BPatch_object::codeBase
+ // Returns the loading address of the object
+ API_EXPORT(Int, (),
+
+ Dyninst::Address,codeBase,());
+
+ // BPatch_object::isSharedLib
+ // Returns true if this object represents a shared library
+ API_EXPORT(Int, (),
+
+ bool,isSharedLib,());
+};
+
+#endif /* _BPatch_object_h_ */
diff --git a/dyninstAPI/make.module.tmpl b/dyninstAPI/make.module.tmpl
index 0d3112a..c0eeaae 100644
--- a/dyninstAPI/make.module.tmpl
+++ b/dyninstAPI/make.module.tmpl
@@ -80,6 +80,7 @@ SRCS += ../src/BPatch.C \
../src/BPatch_process.C \
../src/BPatch_type.C \
../src/BPatch_module.C \
+ ../src/BPatch_object.C \
../src/BPatch_point.C \
../src/BPatch_collections.C \
../src/BPatch_sourceBlock.C \
@@ -161,6 +162,7 @@ PUBLIC_H = BPatch_addressSpace.h \
BPatch_loopTreeNode.h \
BPatch_memoryAccess_NP.h \
BPatch_module.h \
+ BPatch_object.h \
BPatch_parRegion.h \
BPatch_point.h \
BPatch_process.h \
diff --git a/dyninstAPI/src/BPatch_image.C b/dyninstAPI/src/BPatch_image.C
index 151433a..9957dfa 100644
--- a/dyninstAPI/src/BPatch_image.C
+++ b/dyninstAPI/src/BPatch_image.C
@@ -278,6 +278,23 @@ bool BPatch_image::setFuncModulesCallback(BPatch_function *bpf, void *data)
return true;
}
+bool BPatch_image::getObjectsInt(BPatch_Vector<BPatch_object *> &mods)
+{
+ pdvector<mapped_object *> objects;
+ std::vector<AddressSpace *> as;
+ addSpace->getAS(as);
+
+ for (unsigned i=0; i<as.size(); i++) {
+ objects = as[i]->mappedObjects();
+
+ for (unsigned j = 0; j < objects.size(); j++ ) {
+ mods.push_back(new BPatch_object(objects[j]));
+ }
+ }
+
+ return true;
+}
+
bool BPatch_image::getModulesInt(BPatch_Vector<BPatch_module *> &mods)
{
BPatch_Vector<BPatch_module *> *ret = getModulesInt();
diff --git a/dyninstAPI/src/BPatch_object.C b/dyninstAPI/src/BPatch_object.C
new file mode 100644
index 0000000..f01b849
--- /dev/null
+++ b/dyninstAPI/src/BPatch_object.C
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2012 Red Hat Inc.
+ *
+ * We provide the Paradyn Parallel Performance Tools (below
+ * described as "Paradyn") on an AS IS basis, and do not warrant its
+ * validity or performance. We reserve the right to update, modify,
+ * or discontinue this software at any time. We shall have no
+ * obligation to supply such updates or modifications or any other
+ * form of support to you.
+ *
+ * By your use of Paradyn, you understand and agree that we (or any
+ * other person or entity with proprietary rights in Paradyn) are
+ * under no obligation to provide either maintenance services,
+ * update services, notices of latent defects, or correction of
+ * defects for Paradyn.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#define BPATCH_FILE
+
+#include "BPatch_object.h"
+#include "mapped_object.h"
+
+
+BPatch_object::BPatch_object(mapped_object *obj):
+ obj(obj)
+{
+}
+
+char *
+BPatch_object::getFileNameInt(char *buffer, int length)
+{
+ const string& name = obj->fileName();
+ return strncpy(buffer, name.c_str(), length);
+}
+
+char *
+BPatch_object::getFullNameInt(char *buffer, int length)
+{
+ const string& name = obj->fullName();
+ return strncpy(buffer, name.c_str(), length);
+}
+
+Dyninst::Address
+BPatch_object::codeAbsInt()
+{
+ return obj->codeAbs();
+}
+
+Dyninst::Address
+BPatch_object::codeBaseInt()
+{
+ return obj->codeBase();
+}
+
+bool
+BPatch_object::isSharedLibInt()
+{
+ return obj->isSharedLib();
+}
|