Hi, Apologies for replying late. The issue can be reproduced on Ubuntu. Please get the attached files & copy to some folder. If golang and Dyninst 10.2.1 version are installed on system then please follow the below steps: 1. export PATH_TO_DYNINST_LIB= <path to lib folder where dyninst libraries are installed, if not under /usr/local/lib>makeThis will create c++ binary testfile 2. compile golang program usinggo build wrapecho.goThis will create wrapechoRun wrapecho (./wrapecho) from terminal 1 and run testfile (./testfile wrapecho) from terminal 2. testfile will print the number of arguments and each argument name for each function of wrapecho (like Hellocat,hello) 3. compile golang program using linkshared option go build -linkshared wrapecho.goThis will create wrapecho if above command does not work then use below two commands:go install -buildmode=shared stdgo build -linkshared wrapecho.go
Run wrapecho (./wrapecho) from terminal 1 and run testfile (./testfile wrapecho)testfile will print 0 number of arguments for each function. Please let me know if anything is required to reproduce the issue. Thanks On Sunday, 7 February, 2021, 4:40:44 pm IST, Florian Weimer <fwei...@redhat.com> wrote: * Mark Wielaard: > Hi Manoj, > > On Sat, 2021-02-06 at 07:03 +0000, Manoj Kumar via Elfutils-devel > wrote: >> Hi,Using dyninst, I am trying to access local variables and arguments >> of a function which is part of a go binary.To get local variables, >> dyninst uses libdw to find all the modules. It uses dwarf_nextcu >> function of libdw to find all the modules of binary.When I compile a >> go binary using "go build filename.go" then dwarf_nextcu finds all >> the modules (almost 118) and dyninst is able to access local >> variables and arguments of any function.But when I compile a go >> binary with linkshared option "go build -linkshared filename.go" >> then dwarf_nextcu finds only 5 modules. Due to that, dyninst is not >> able to access any variable of a function. >> Does go binary with linkshared option has different version of dwarf? >> Could you please suggest how to use libdw for go binary with >> linkshared option. > > Could you explain what the linkshared option is and what it does? $ go tool link -help […] -linkshared link against installed Go shared libraries […] The Fedora version is broken, unfortunately: $ cat t.go package main func main() { } $ go build -linkshared t.go go build runtime/internal/sys: copying /home/fweimer/.cache/go-build/ef/ef8092ebd194e7ec34c864584fc2216541454e9626c98ffe9d5210d2784da429-d: open /usr/lib/golang/pkg/linux_amd64_dynlink/runtime/internal/sys.a: permission denied go build internal/cpu: copying /home/fweimer/.cache/go-build/ca/ca0a2dbbc130aa21613ca27f378b8c9fda02c4082687d92b40a0d6c660bc86d1-d: open /usr/lib/golang/pkg/linux_amd64_dynlink/internal/cpu.a: permission denied […] $ rpm -qf /usr/bin/go golang-bin-1.15.7-1.fc33.x86_64 Filed here: <https://bugzilla.redhat.com/show_bug.cgi?id=1688261> So I'm not sure how we can reproduce the elfutils issue. 8-/ Thanks, Florian -- Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn, Commercial register: Amtsgericht Muenchen, HRB 153243, Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill
Makefile
Description: Binary data
#include <cstdlib> #include <iostream> #include <vector> #include <string> using namespace std; // Command line parsing #include <getopt.h> // DyninstAPI includes #include "BPatch.h" #include "BPatch_binaryEdit.h" #include "BPatch_flowGraph.h" #include "BPatch_function.h" #include "BPatch_point.h" #include "BPatch_object.h" #include "BPatch_module.h" #include "Type.h" #ifdef HAVE_SELINUX #include <selinux/selinux.h> #endif using namespace Dyninst; /* Every Dyninst mutator needs to declare one instance of BPatch */ BPatch bpatch; int main (int argc, char *argv[]) { if(argc < 2) { cerr << "./codeCoverage inputbinary" << endl; return EXIT_FAILURE; } char *inputprogram = argv[1]; pid_t pid ; char line[512]; FILE * command = NULL; char strPID[100]; sprintf(strPID,"pidof -s %s",inputprogram); command = popen(strPID,"r"); fgets(line,512,command); pid = strtoul(line,NULL,10); pclose(command); cerr << "pid of process " << pid << endl; BPatch_addressSpace* app2 = bpatch.processAttach (NULL, pid); if (app2 == NULL) { cerr << "Failed to attach to the process" << endl; return EXIT_FAILURE; } BPatch_process* appProc = dynamic_cast<BPatch_process*>(app2); if (appProc == NULL ) { cerr << "BPatch_process is NULL" << endl; return EXIT_FAILURE; } BPatch_image *appImage = appProc->getImage (); if (appImage == NULL) { cerr << "Failed to get image" << endl; return EXIT_FAILURE; } vector < BPatch_module * >*modules = appImage->getModules (); vector < BPatch_module * >::iterator moduleIter; for (moduleIter = modules->begin (); moduleIter != modules->end (); ++moduleIter) { char moduleName[1024]; (*moduleIter)->getName (moduleName, 1024); vector < BPatch_function * >*allFunctions = (*moduleIter)->getProcedures (); vector < BPatch_function * >::iterator funcIter; for (funcIter = allFunctions->begin (); funcIter != allFunctions->end (); ++funcIter) { BPatch_function *curFunc = *funcIter; char funcName[1024]; curFunc->getName (funcName, 1024); if(strstr(funcName, "main.")!= NULL){ BPatch_Vector<BPatch_localVar *> *vars = curFunc->getParams(); cout<<"num vars in " << funcName << " are " << vars->size() << " type " << curFunc->getReturnType()<< endl; for (unsigned int i = 0; i < vars->size(); ++i) { cout << "var name is " << (*vars)[i]->getName() << endl; cout << "local var " << (*vars)[i]->getSymtabVar() << endl; } } } } cout << "end main" <<endl; appProc->continueExecution(); appProc->detach(true); return EXIT_SUCCESS; }
package main import ( "C" "fmt" "github.com/labstack/echo" "net/http" ) func main() { e := echo.New() fmt.Println("Inside Client Echo Code!") fmt.Println(e) e.GET("/", hello) e.GET("/cat", Hellocat) e.Logger.Fatal(e.Start(":1323")) fmt.Println("Closed---------!") } func hello(c echo.Context) error { fmt.Println("Inside hello") return c.String(http.StatusOK, "Hello, World!") } func Hellocat(c echo.Context) error { //testsimplefunc() fmt.Println("Inside hellocat") return c.String(http.StatusOK, "Hello, Cat!") }