[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v3 41/45] windbg: implemented kd_api_search_memo
From: |
Ladi Prosek |
Subject: |
Re: [Qemu-devel] [PATCH v3 41/45] windbg: implemented kd_api_search_memory |
Date: |
Wed, 29 Nov 2017 08:55:45 +0100 |
On Tue, Nov 21, 2017 at 3:11 PM, Mihail Abakumov
<address@hidden> wrote:
> Signed-off-by: Mihail Abakumov <address@hidden>
> Signed-off-by: Pavel Dovgalyuk <address@hidden>
> Signed-off-by: Dmitriy Koltunov <address@hidden>
> ---
> include/exec/windbgstub-utils.h | 1 +
> windbgstub-utils.c | 33 +++++++++++++++++++++++++++++++++
> windbgstub.c | 4 ++++
> 3 files changed, 38 insertions(+)
>
> diff --git a/include/exec/windbgstub-utils.h b/include/exec/windbgstub-utils.h
> index 73d49b774d..c2eb8a75a7 100755
> --- a/include/exec/windbgstub-utils.h
> +++ b/include/exec/windbgstub-utils.h
> @@ -102,6 +102,7 @@ void kd_api_write_physical_memory(CPUState *cpu,
> PacketData *pd);
> void kd_api_get_version(CPUState *cpu, PacketData *pd);
> void kd_api_read_msr(CPUState *cpu, PacketData *pd);
> void kd_api_write_msr(CPUState *cpu, PacketData *pd);
> +void kd_api_search_memory(CPUState *cpu, PacketData *pd);
> void kd_api_unsupported(CPUState *cpu, PacketData *pd);
>
> SizedBuf kd_gen_exception_sc(CPUState *cpu);
> diff --git a/windbgstub-utils.c b/windbgstub-utils.c
> index 7ef301bac7..1f4590f338 100755
> --- a/windbgstub-utils.c
> +++ b/windbgstub-utils.c
> @@ -261,6 +261,39 @@ void kd_api_get_version(CPUState *cpu, PacketData *pd)
> }
> }
>
> +void kd_api_search_memory(CPUState *cpu, PacketData *pd)
> +{
> + DBGKD_SEARCH_MEMORY *m64c = &pd->m64.u.SearchMemory;
> + int s_len = MAX(ldq_p(&m64c->SearchLength), 1);
> + int p_len = MIN(ldl_p(&m64c->PatternLength), pd->extra_size);
> + target_ulong addr = ldq_p(&m64c->SearchAddress);
> + int size = MIN(s_len, 10);
> + uint8_t mem[size + p_len];
Is this allocation bounded by a reasonably small number? What's the
maximum PatternLength?
> + int i, err;
> +
> + pd->extra_size = 0;
> + pd->m64.ReturnStatus = STATUS_NO_MORE_ENTRIES;
> +
> + while (s_len) {
> + err = cpu_memory_rw_debug(cpu, addr, mem, size + p_len, 0);
> + if (!err) {
> + for (i = 0; i < size; ++i) {
> + if (memcmp(mem + i, pd->extra, p_len) == 0) {
> + stl_p(&m64c->FoundAddress, addr + i);
> + pd->m64.ReturnStatus = STATUS_SUCCESS;
> + return;
> + }
> + }
> + } else {
> + WINDBG_DEBUG("search_memory: No physical page mapped: " FMT_ADDR,
> + addr);
> + }
> + s_len -= size;
> + addr += size;
> + size = MIN(s_len, 10);
> + }
> +}
> +
Too bad that you can't use memmem(). This implementation screams
O(N^2) to me. One of the things that can be improved later I guess.
I would at least up the step from 10 to 1024 so we don't call
cpu_memory_rw_debug() that often.
> void kd_api_unsupported(CPUState *cpu, PacketData *pd)
> {
> WINDBG_ERROR("Caught unimplemented api %s",
> diff --git a/windbgstub.c b/windbgstub.c
> index 0268d0818e..d35ff6ba96 100755
> --- a/windbgstub.c
> +++ b/windbgstub.c
> @@ -212,6 +212,10 @@ static void
> windbg_process_manipulate_packet(ParsingContext *ctx)
> case DbgKdClearAllInternalBreakpointsApi:
> return;
>
> + case DbgKdSearchMemoryApi:
> + kd_api_search_memory(cpu, &ctx->data);
> + break;
> +
> default:
> kd_api_unsupported(cpu, &ctx->data);
> break;
>
- [Qemu-devel] [PATCH v3 35/45] windbg: debug exception subscribing, (continued)
- [Qemu-devel] [PATCH v3 35/45] windbg: debug exception subscribing, Mihail Abakumov, 2017/11/21
- [Qemu-devel] [PATCH v3 36/45] windbg: implemented kd_api_continue, Mihail Abakumov, 2017/11/21
- [Qemu-devel] [PATCH v3 37/45] windbg: implemented kd_api_read_io_space and kd_api_write_io_space, Mihail Abakumov, 2017/11/21
- [Qemu-devel] [PATCH v3 38/45] windbg: implemented kd_api_read_physical_memory and kd_api_write_physical_memory, Mihail Abakumov, 2017/11/21
- [Qemu-devel] [PATCH v3 39/45] windbg: implemented kd_api_get_version, Mihail Abakumov, 2017/11/21
- [Qemu-devel] [PATCH v3 40/45] windbg: implemented kd_api_read_msr and kd_api_write_msr, Mihail Abakumov, 2017/11/21
- [Qemu-devel] [PATCH v3 41/45] windbg: implemented kd_api_search_memory, Mihail Abakumov, 2017/11/21
- Re: [Qemu-devel] [PATCH v3 41/45] windbg: implemented kd_api_search_memory,
Ladi Prosek <=
- [Qemu-devel] [PATCH v3 42/45] windbg: implemented kd_api_fill_memory, Mihail Abakumov, 2017/11/21
- [Qemu-devel] [PATCH v3 43/45] windbg: implemented kd_api_query_memory, Mihail Abakumov, 2017/11/21
- [Qemu-devel] [PATCH v3 44/45] windbg: added new api functions, Mihail Abakumov, 2017/11/21
- [Qemu-devel] [PATCH v3 45/45] windbg: implemented kd_api_get_context_ex and kd_api_set_context_ex, Mihail Abakumov, 2017/11/21
- Re: [Qemu-devel] [PATCH v3 00/45] Windbg supporting, no-reply, 2017/11/21
- Re: [Qemu-devel] [PATCH v3 00/45] Windbg supporting, no-reply, 2017/11/22
- Re: [Qemu-devel] [PATCH v3 00/45] Windbg supporting, no-reply, 2017/11/22