劇集
重組工具 #170 - 調試程式 - JavaScript 腳本
在重組工具的這一集,安德魯·理查茲從 Windows 偵錯工具小組與 Andy Luhrs 和 Bill Messmer 交談。 我們將討論 WDK 和 SDK 組建 14951 和更新版本中可用的 WinDbg 中新的 JavaScript 擴充性和腳本功能。
- 博客- https://blogs.msdn.microsoft.com/windbg/
- 電子郵件- windbgfb@microsoft.com
Bill 利用了先前在這些情節中的調試程序物件模型:
時間軸:
[00:00] 歡迎和簡介
[00:24] 新增 SDK 卸除
[00:29] 為什麼 JavaScript
[02:07] 新增命令
[03:50] Visual Studio Code
[04:00] 範例 - Hello World
[07:15] 調試程序預設命名空間
[09:07] 範例 - 列印所有線程
[10:26] 範例 - 條件斷點
[18:13] 'g' 與 'gc' – 安德魯是對的! 'gc' 會以與啟動相同的方式繼續執行。 因此,如果您叫用 'p',然後叫用條件式斷點,其中含有 'gc','gc' 只會完成您的初始 'p'。
[20:40] 範例 - 唯一堆棧
[34:40] 範例 - 加法
問題/批注? 透過電子郵件傳送給我們 defragtools@microsoft.com
JavaScript MSDN Docs:
唯一堆棧範例(右側範例):
“use strict”;
類別 __stackEntry { 建構函式(frameString) { this.threads = []; this.frameString = frameString; this.children = new Map(; }
display(indent)
{
for (var child of this.children.values())
{
host.diagnostics.debugLog(indent, child.frameString, " [Threads In Branch: ");
for (var thread of child.threads)
{
host.diagnostics.debugLog(thread.Id, " ");
}
host.diagnostics.debugLog("]\n");
child.display(indent + " ");
}
}
}
class __stackMap { constructor(process) { this.__process = process; this.__root = new __stackEntry(“”];this.build():}
build()
{
for (var thread of this.__process.Threads)
{
var current = this.__root;
var frameNum = 0;
var frameCount = thread.Stack.Frames.Count();
for (var frameNum = frameCount - 1; frameNum >= 0; --frameNum) {
var frame = thread.Stack.Frames[frameNum];
var frameString = frame.toString();
if (current.children.has(frameString)) {
current = current.children.get(frameString);
current.threads.push(thread);
}
else {
var newEntry = new __stackEntry(frameString);
current.children.set(frameString, newEntry);
current = newEntry;
current.threads.push(thread);
}
}
}
}
findEntry(thread)
{
var current = this.__root;
var frameCount = thread.Stack.Frames.Count();
for (var frameNum = frameCount - 1; frameNum >= 0; --frameNum)
{
var frame = thread.Stack.Frames[frameNum];
var frameString = frame.toString();
if (!current.children.has(frameString))
{
return null;
}
current = current.children.get(frameString);
}
return current;
}
display()
{
this.__root.display("");
}
}
類別 __threadSameStacks { constructor(thread) { this.__thread = thread; }
getDimensionality()
{
return 1;
}
getValueAt(idx)
{
for (var idxVal of this)
{
var tid = idxVal[Symbol.indicies][0];
if (idxVal[Symbol.indicies][0] == idx && tid != this.__thread.Id)
{
return idxVal.value;
}
}
return undefined;
}
*[Symbol.iterator]()
{
var context = this.__thread.hostContext;
var session = host.namespace.Debugger.Sessions.getValueAt(context);
var process = session.Processes.getValueAt(context);
var map = new __stackMap(process);
var entry = map.findEntry(this.__thread);
if (entry != null)
{
for (var sharingThread of entry.threads)
{
if (sharingThread.Id != this.__thread.Id)
{
yield new host.indexedValue(sharingThread, [sharingThread.Id]);
}
}
}
}
}
class __threadExtension { get IdenticalStacks() { return new __threadSameStacks(this; } }
function invokeScript() { var map = new __stackMap(host.currentProcess; map.display(): }
function initializeScript() { return [new host.namedModelParent(__threadExtension, “Debugger.Models.Thread”)]; }
在重組工具的這一集,安德魯·理查茲從 Windows 偵錯工具小組與 Andy Luhrs 和 Bill Messmer 交談。 我們將討論 WDK 和 SDK 組建 14951 和更新版本中可用的 WinDbg 中新的 JavaScript 擴充性和腳本功能。
- 博客- https://blogs.msdn.microsoft.com/windbg/
- 電子郵件- windbgfb@microsoft.com
Bill 利用了先前在這些情節中的調試程序物件模型:
時間軸:
[00:00] 歡迎和簡介
[00:24] 新增 SDK 卸除
[00:29] 為什麼 JavaScript
[02:07] 新增命令
[03:50] Visual Studio Code
[04:00] 範例 - Hello World
[07:15] 調試程序預設命名空間
[09:07] 範例 - 列印所有線程
[10:26] 範例 - 條件斷點
[18:13] 'g' 與 'gc' – 安德魯是對的! 'gc' 會以與啟動相同的方式繼續執行。 因此,如果您叫用 'p',然後叫用條件式斷點,其中含有 'gc','gc' 只會完成您的初始 'p'。
[20:40] 範例 - 唯一堆棧
[34:40] 範例 - 加法
問題/批注? 透過電子郵件傳送給我們 defragtools@microsoft.com
JavaScript MSDN Docs:
唯一堆棧範例(右側範例):
“use strict”;
類別 __stackEntry { 建構函式(frameString) { this.threads = []; this.frameString = frameString; this.children = new Map(; }
display(indent)
{
for (var child of this.children.values())
{
host.diagnostics.debugLog(indent, child.frameString, " [Threads In Branch: ");
for (var thread of child.threads)
{
host.diagnostics.debugLog(thread.Id, " ");
}
host.diagnostics.debugLog("]\n");
child.display(indent + " ");
}
}
}
class __stackMap { constructor(process) { this.__process = process; this.__root = new __stackEntry(“”];this.build():}
build()
{
for (var thread of this.__process.Threads)
{
var current = this.__root;
var frameNum = 0;
var frameCount = thread.Stack.Frames.Count();
for (var frameNum = frameCount - 1; frameNum >= 0; --frameNum) {
var frame = thread.Stack.Frames[frameNum];
var frameString = frame.toString();
if (current.children.has(frameString)) {
current = current.children.get(frameString);
current.threads.push(thread);
}
else {
var newEntry = new __stackEntry(frameString);
current.children.set(frameString, newEntry);
current = newEntry;
current.threads.push(thread);
}
}
}
}
findEntry(thread)
{
var current = this.__root;
var frameCount = thread.Stack.Frames.Count();
for (var frameNum = frameCount - 1; frameNum >= 0; --frameNum)
{
var frame = thread.Stack.Frames[frameNum];
var frameString = frame.toString();
if (!current.children.has(frameString))
{
return null;
}
current = current.children.get(frameString);
}
return current;
}
display()
{
this.__root.display("");
}
}
類別 __threadSameStacks { constructor(thread) { this.__thread = thread; }
getDimensionality()
{
return 1;
}
getValueAt(idx)
{
for (var idxVal of this)
{
var tid = idxVal[Symbol.indicies][0];
if (idxVal[Symbol.indicies][0] == idx && tid != this.__thread.Id)
{
return idxVal.value;
}
}
return undefined;
}
*[Symbol.iterator]()
{
var context = this.__thread.hostContext;
var session = host.namespace.Debugger.Sessions.getValueAt(context);
var process = session.Processes.getValueAt(context);
var map = new __stackMap(process);
var entry = map.findEntry(this.__thread);
if (entry != null)
{
for (var sharingThread of entry.threads)
{
if (sharingThread.Id != this.__thread.Id)
{
yield new host.indexedValue(sharingThread, [sharingThread.Id]);
}
}
}
}
}
class __threadExtension { get IdenticalStacks() { return new __threadSameStacks(this; } }
function invokeScript() { var map = new __stackMap(host.currentProcess; map.display(): }
function initializeScript() { return [new host.namedModelParent(__threadExtension, “Debugger.Models.Thread”)]; }
有任何意見嗎? 請在此提交問題。