Example #1
0
HRESULT CALLBACK
info_local(PDEBUG_CLIENT4 Client, PCSTR args)
{
    if (!enter_command(Client))
        return E_FAIL;

    HRESULT hr;
    DEBUG_STACK_FRAME frames[MAX_FRAMES];
    ULONG frameFilled = 0;
    if (gDebugControl->GetStackTrace(0,		// frame offset
                                     0,		// stack offset
                                     0,		// instruction offset
                                     frames,
                                     MAX_FRAMES,
                                     &frameFilled) != S_OK )
        goto Fail;

    PDEBUG_SYMBOL_GROUP2 symbolGroup2 = NULL;
    for (ULONG frame_num = 0; frame_num < frameFilled; frame_num++)
    {
        // Set scope to frame n
        // Beware, this method returns S_FALSE
        hr = gDebugSymbols3->SetScopeFrameByIndex(frame_num);
        if (FAILED(hr))
            break;
        dprintf("-------- frame %d fp="PRINT_FORMAT_POINTER" sp="PRINT_FORMAT_POINTER" --------\n",
                frame_num, frames[frame_num].FrameOffset, frames[frame_num].StackOffset);
        // Get the function name
        dprintf("Function:\n");
        char func_name[NAME_BUF_SZ];
        ULONG64 displacement = 0;
        hr = gDebugSymbols3->GetNameByOffset(frames[frame_num].InstructionOffset, func_name, NAME_BUF_SZ, NULL, &displacement);
        if (SUCCEEDED(hr))
            dprintf("\t%s() +%d\n", func_name, displacement);
        // Retrieve COM interface to symbols of this scope (frame)
        if (gDebugSymbols3->GetScopeSymbolGroup2(DEBUG_SCOPE_GROUP_ARGUMENTS, symbolGroup2, &symbolGroup2) != S_OK)
            goto Fail;
        dprintf("Parameters:\n");
        print_sym_group(symbolGroup2);
        if (gDebugSymbols3->GetScopeSymbolGroup2(DEBUG_SCOPE_GROUP_LOCALS, symbolGroup2, &symbolGroup2) != S_OK)
            goto Fail;
        dprintf("Local Variables:\n");
        print_sym_group(symbolGroup2);
        // line separator
        dprintf("\n");
    }

    goto NormalExit;

Fail:
    dprintf("Failed to query debug engine COM interface\n");
NormalExit:
    if (symbolGroup2)
        symbolGroup2->Release();

    leave_command();
    return S_OK;
}
Example #2
0
HRESULT CALLBACK
shrobj_level(PDEBUG_CLIENT4 Client, PCSTR args)
{
    if (!enter_command(Client))
        return E_FAIL;

    unsigned int level = 0;
    if (args && strlen(args))
        level = (unsigned int) GetExpression(args);

    set_shared_objects_indirection_level(level);

    leave_command();
    return S_OK;
}
Example #3
0
HRESULT CALLBACK
obj(PDEBUG_CLIENT4 Client, PCSTR args)
{
    if (!enter_command(Client))
        return E_FAIL;

    if (!args || strlen(args)==0)
    {
        dprintf("Please see help for this command's usage\n");
        return E_FAIL;
    }

    search_cplusplus_objects_and_references (args);

    leave_command();
    return S_OK;
}
Example #4
0
HRESULT CALLBACK
shrobj(PDEBUG_CLIENT4 Client, PCSTR args)
{
    if (!enter_command(Client))
        return E_FAIL;

    struct CA_LIST* threads = ca_list_new();
    int* p;

    if (args && strlen(args))
    {
        char* buf = strdup(args);
        char* options[MAX_NUM_OPTIONS];
        int num_options = ca_parse_options(buf, options);
        int i;

        for (i = 0; i < num_options; i++)
        {
            char* option = options[i];
            int tid = atoi(option);
            if (tid >= 0)
            {
                p = (int*) malloc(sizeof(int));
                *p = tid;
                ca_list_push_front(threads, p);
            }
        }
        free(buf);
    }

    find_shared_objects_by_threads(threads);
    // cleanup thread list
    if (!ca_list_empty(threads))
    {
        ca_list_traverse_start(threads);
        while ( (p = (int*) ca_list_traverse_next(threads)))
        {
            free (p);
        }
    }
    ca_list_delete(threads);

    leave_command();
    return S_OK;
}
Example #5
0
HRESULT CALLBACK
decode (PDEBUG_CLIENT4 Client, PCSTR args)
{
    if (!enter_command(Client))
        return E_FAIL;

    char* dup_args = NULL;
    if (args && strlen(args))
        dup_args = _strdup(args);

    decode_func(dup_args);

    if (dup_args)
        free(dup_args);

    leave_command();
    return S_OK;
}
Example #6
0
/////////////////////////////////////////////////////
// Unexposed cmd to set max recursive reference depth
/////////////////////////////////////////////////////
HRESULT CALLBACK
block_size(PDEBUG_CLIENT4 Client, PCSTR args)
{
    if (!enter_command(Client))
        return E_FAIL;

    if (!args || strlen(args)==0)
    {
        dprintf("0");
        return E_FAIL;
    }
    address_t addr = GetExpression(args);

    struct heap_block heap_block;
    if (addr && get_heap_block_info(addr, &heap_block))
        dprintf(PRINT_FORMAT_SIZE, heap_block.size);
    else
        dprintf("0");

    leave_command();
    return S_OK;
}
Example #7
0
HRESULT CALLBACK
pattern (PDEBUG_CLIENT4 Client, PCSTR args)
{
    if (!enter_command(Client))
        return E_FAIL;

    char* args_buf = NULL;
    if (args && strlen(args))
        args_buf = strdup(args);

    CA_BOOL rc = pattern_command_impl(args_buf);

    if (args_buf)
        free(args_buf);

    leave_command();

    if (rc)
        return S_OK;
    else
        return E_FAIL;
}
Example #8
0
HRESULT CALLBACK
mcache(PDEBUG_CLIENT4 Client, PCSTR args)
{
    if (!enter_command(Client))
        return E_FAIL;

    // read/print global variabls
    ULONG64 addr;

    unsigned int g_cache_max_free_pages;
    if (gDebugSymbols3->GetOffsetByName("shsmp64!g_cache_max_free_pages", &addr) != S_OK
            || !inferior_memory_read(addr, &g_cache_max_free_pages, sizeof(g_cache_max_free_pages)))
    {
        dprintf("Failed to read shsmp64!g_cache_max_free_pages\n");
        goto McacheExit;
    }
    dprintf("Max 64KB small/medium pages to cache: %d\n", g_cache_max_free_pages);

    unsigned int g_cache_free_pages_total;
    if (gDebugSymbols3->GetOffsetByName("shsmp64!g_cache_free_pages_total", &addr) != S_OK
            || !inferior_memory_read(addr, &g_cache_free_pages_total, sizeof(g_cache_free_pages_total)))
    {
        dprintf("Failed to read shsmp64!g_cache_free_pages_total\n");
        goto McacheExit;
    }
    dprintf("Currently cached %d pages\n\n", g_cache_free_pages_total);

    size_t g_max_cache_block_size;
    if (gDebugSymbols3->GetOffsetByName("shsmp64!g_max_cache_block_size", &addr) != S_OK
            || !inferior_memory_read(addr, &g_max_cache_block_size, sizeof(g_max_cache_block_size)))
    {
        dprintf("Failed to read shsmp64!g_max_cache_block_size\n");
        goto McacheExit;
    }
    dprintf("Max size to cache: %ldKB\n", g_max_cache_block_size/1024);

    unsigned int g_max_cache_blocks_per_band;
    if (gDebugSymbols3->GetOffsetByName("shsmp64!g_max_cache_blocks_per_band", &addr) != S_OK
            || !inferior_memory_read(addr, &g_max_cache_blocks_per_band, sizeof(g_max_cache_blocks_per_band)))
    {
        dprintf("Failed to read shsmp64!g_max_cache_blocks_per_band\n");
        goto McacheExit;
    }
    dprintf("Max number of cached blocks per band: %d\n", g_max_cache_blocks_per_band);

    size_t g_max_cache_size;
    if (gDebugSymbols3->GetOffsetByName("shsmp64!g_max_cache_size", &addr) != S_OK
            || !inferior_memory_read(addr, &g_max_cache_size, sizeof(g_max_cache_size)))
    {
        dprintf("Failed to read shsmp64!g_max_cache_size\n");
        goto McacheExit;
    }
    dprintf("Max total size to cache: %ldMB\n\n", g_max_cache_size/(1024*1024));

    CacheBlock* g_cache_lists_heads[MAX_NUM_BANDS];
    if (gDebugSymbols3->GetOffsetByName("shsmp64!g_cache_lists_heads", &addr) != S_OK
            || !inferior_memory_read(addr, &g_cache_lists_heads, sizeof(g_cache_lists_heads)))
    {
        dprintf("Failed to read shsmp64!g_cache_lists_heads\n");
        goto McacheExit;
    }
    unsigned int g_cache_lists_sizes[MAX_NUM_BANDS];
    if (gDebugSymbols3->GetOffsetByName("shsmp64!g_cache_lists_sizes", &addr) != S_OK
            || !inferior_memory_read(addr, &g_cache_lists_sizes, sizeof(g_cache_lists_sizes)))
    {
        dprintf("Failed to read shsmp64!g_cache_lists_sizes\n");
        goto McacheExit;
    }
    size_t g_total_cache_size;
    if (gDebugSymbols3->GetOffsetByName("shsmp64!g_total_cache_size", &addr) != S_OK
            || !inferior_memory_read(addr, &g_total_cache_size, sizeof(g_total_cache_size)))
    {
        dprintf("Failed to read shsmp64!g_total_cache_size\n");
        goto McacheExit;
    }

    dprintf("Size(KB)\t#Blocks\tTotal_Size(KB)\n");
    int i;
    size_t sz, totalSz=0;
    for (i = 0, sz = 64*1024; i < MAX_NUM_BANDS; i++)
    {
        unsigned int listsz = 0;
        CacheBlock* pblock = g_cache_lists_heads[i];
        while (pblock)
        {
            listsz++;
            CacheBlock cblock;
            if (!inferior_memory_read((address_t)pblock, &cblock, sizeof(cblock)))
            {
                dprintf("Failed to read CacheBlock at %p\n", pblock);
                break;
            }
            pblock = cblock.next;
        }
        if (listsz != g_cache_lists_sizes[i])
        {
            dprintf("Band %d list size doesn't match! %d <=> %d\n",
                    i, listsz, g_cache_lists_sizes[i]);
        }
        else
            dprintf("%ld\t\t%d\t\t%ld\n", sz/1024, listsz, sz*listsz/1024);
        totalSz += (sz - 0x80) * listsz;
        sz = sz << 1;
    }
    dprintf("------------------------------------------\n");
    dprintf("\t\t\t\t%ld MB\n", totalSz/(1024*1024));

McacheExit:
    leave_command();
    return S_OK;
}
vint8 class_base_module::initialize()
{
  enter_command("c_code_dir", &class_base_module::c_code_dir);
  enter_command("c_data_dir", &class_base_module::c_data_dir);

  enter_command("d_code_dir", &class_base_module::d_code_dir);
  enter_command("d_data_dir", &class_base_module::d_data_dir);

  enter_command("l_code_dir", &class_base_module::l_code_dir);
  enter_command("l_data_dir", &class_base_module::l_data_dir);
  enter_command("list_commands", &class_base_module::list_all_commands);

  enter_command("randomize", &class_base_module::randomize);
  enter_command("r_code_dir", &class_base_module::r_code_dir);
  enter_command("r_data_dir", &class_base_module::r_data_dir);

  enter_command("s_data_dir", &class_base_module::s_data_dir);
  enter_command("set_code_dir", &class_base_module::set_code_dir);
  enter_command("set_data_dir", &class_base_module::set_data_dir);
  enter_command("set_nessie", &class_base_module::set_nessie);
  enter_command("system", &class_base_module::system_function);
  

  return 1;
}