2017-03-10 40 views
-1

我希望能夠調用以下方法。它返回一個C字符串。在WinDBG中調用C++方法實例並打印結果

在GDB中,我使用這個調用來打印結果。請注意,我需要在調用它之前設置正確的線程和框架,以便kCurrentScope實例可用。

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

有沒有辦法在CDB/WinDbg中做到這一點?

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

有趣的是,Windows甚至沒有看到這個功能。它被定義爲

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 {}; 
    } 
} 

搜索符號返回

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)' 
+2

它可能是功能已經被內聯在所有的呼叫者和身體優化爲未使用? –

+0

它似乎沒有內聯。有沒有辦法從符號中知道? –

回答

0

你可以嘗試用pykd做到這一點(有某些限制) See example

+0

這假定可以從WinDBG調用函數。如果原始問題可以解決,PyKd會很棒。 –

+0

PyKD可以調用函數和類方法(有一些限制:只支持參數的整型)。 – ussrhero

+0

你能提供一個可靠的例子嗎? –