Episode

Defrag Tools #170 - Debugger - JavaScript Scripting

Dalam episode Defrag Tools ini, Andrew Richards berbicara dengan Andy Luhrs dan Bill Messmer dari tim Debugging Tools for Windows. Kami berbicara tentang ekstensibilitas JavaScript baru dan kemampuan pembuatan skrip di WinDbg yang tersedia di WDK dan SDK build 14951 dan yang lebih baru.

Bill memanfaatkan model objek debugger sebelumnya dalam episode ini:

Timeline:

[00:00] Selamat datang dan perkenalan
[00:24] Penghilangan SDK baru
[00:29] Mengapa JavaScript
[02:07] Perintah baru
[03:50] Visual Studio Code
[04:00] Contoh - Halo Dunia
[07:15] Namespace default debugger
[09:07] Contoh - Cetak semua utas
[10:26] Contoh - Titik henti bersyar
[18:13] 'g' vs. 'gc' - Andrew benar! 'gc' melanjutkan eksekusi dengan cara yang sama seperti dimulai. Jadi jika Anda menekan 'p' dan kemudian mencapai titik henti bersyarat yang memiliki 'gc' di dalamnya, 'gc' hanya akan menyelesaikan 'p' awal Anda.
[20:40] Contoh - Tumpukan unik
[34:40] Contoh - Penambahan

Pertanyaan/Komentar? Kirim email kepada kami di defragtools@microsoft.com

Dokumen JavaScript MSDN:

Contoh Tumpukan Unik (yang kanan):

"gunakan ketat";

class __stackEntry { constructor(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("");
}

}

class __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(); }

fungsi initializeScript() { return [new host.namedModelParent(__threadExtension, "Debugger.Models.Thread")]; }