Calling a C++ method instance in WinDBG and printing the results

0

I have the following method I want to be able to invoke. It returns a C string.

In GDB I use this call to print the result. Note that I need to set the proper thread and frame before invoking it, such that the kCurrentScope instance is available.

printf "%s\n", mongo::mozjs::kCurrentScope->buildStackString().c_str()

Is there a way to do this in CDB/WinDbg?

0:002> x mongo!mongo::mozjs::kCurrentScope
000000bb`46c318f0 mongo!mongo::mozjs::kCurrentScope = 0x000000bb`4b7088a0

The interesting thing is that Windows does not even see this function. It is defined as

std::string MozJSImplScope::buildStackString() {
   JS::RootedObject stack(_context);

   if (! JS::CaptureCurrentStack(_context, &stack)) {
       return {};
   }

   JS::RootedString out(_context);
   if (JS::BuildStackString(_context, stack, &out, 0)) {
       return JSStringWrapper(_context, out.get()).toString();
   } else {
       return {};
   }
}

Searching for the symbol returns

0:002> x mongo!*buildStackString*
00007ff7`c387db40 mongo!JS::BuildStackString (struct JSContext *, class JS::Handle<JSObject *>, class JS::MutableHandle<JSString *>, unsigned int64)
00007ff7`c3b266cc mongo!`JS::BuildStackString'::`1'::dtor$9 (class JS::Handle<JSObject *>, class JS::MutableHandle<JSString *>)
00007ff7`c3b266c0 mongo!`JS::BuildStackString'::`1'::dtor$8 (class JS::Handle<JSObject *>, class JS::MutableHandle<JSString *>)
00007ff7`c3b266b4 mongo!`JS::BuildStackString'::`1'::dtor$1 (class JS::Handle<JSObject *>, class JS::MutableHandle<JSString *>)
00007ff7`c3b26680 mongo!`JS::BuildStackString'::`1'::dtor$0 (class JS::Handle<JSObject *>, class JS::MutableHandle<JSString *>)
00007ff7`c3b266e4 mongo!`JS::BuildStackString'::`1'::dtor$3 (class JS::Handle<JSObject *>, class JS::MutableHandle<JSString *>)
00007ff7`c3b266d8 mongo!`JS::BuildStackString'::`1'::dtor$2 (class JS::Handle<JSObject *>, class JS::MutableHandle<JSString *>)
00007ff7`c3b266fc mongo!`JS::BuildStackString'::`1'::dtor$5 (class JS::Handle<JSObject *>, class JS::MutableHandle<JSString *>)
00007ff7`c3b266f0 mongo!`JS::BuildStackString'::`1'::dtor$4 (class JS::Handle<JSObject *>, class JS::MutableHandle<JSString *>)
00007ff7`c3b26698 mongo!`JS::BuildStackString'::`1'::dtor$7 (class JS::Handle<JSObject *>, class JS::MutableHandle<JSString *>)
00007ff7`c3b2668c mongo!`JS::BuildStackString'::`1'::dtor$6 (class JS::Handle<JSObject *>, class JS::MutableHandle<JSString *>)


0:002> .call mongo!mongo::mozjs::buildStackString(kCurrentScope)
Couldn't resolve error at 'mongo!mongo::mozjs::buildStackString(kCurrentScope)'
0:002> .call mongo!mongo::mozjs::buildStackString(mongo!mongo::mozjs::kCurrentScope)
Couldn't resolve error at 'mongo!mongo::mozjs::buildStackString(mongo!mongo::mozjs::kCurrentScope)'
c++
debugging
gdb
windbg
asked on Stack Overflow Mar 10, 2017 by Jonathan Abrahams • edited Mar 11, 2017 by Employed Russian

1 Answer

0

You can try to do it with pykd ( with some restrictions ) See example

answered on Stack Overflow Mar 11, 2017 by ussrhero

User contributions licensed under CC BY-SA 3.0