CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
99 lines
2.8 KiB
C
99 lines
2.8 KiB
C
/* Self tests for simple_search_memory for GDB, the GNU debugger.
|
|
|
|
Copyright (C) 2020-2024 Free Software Foundation, Inc.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#include "gdbsupport/selftest.h"
|
|
#include "gdbsupport/search.h"
|
|
|
|
namespace selftests {
|
|
namespace search_memory_tests {
|
|
|
|
static void
|
|
run_tests ()
|
|
{
|
|
size_t size = 2 * SEARCH_CHUNK_SIZE + 1;
|
|
|
|
std::vector<gdb_byte> data (size);
|
|
data[size - 1] = 'x';
|
|
|
|
bool read_fully = false;
|
|
bool read_off_end = false;
|
|
auto read_memory = [&] (CORE_ADDR from, gdb_byte *out, size_t len)
|
|
{
|
|
if (from + len > data.size ())
|
|
read_off_end = true;
|
|
else
|
|
memcpy (out, &data[from], len);
|
|
if (from + len == data.size ())
|
|
read_fully = true;
|
|
return true;
|
|
};
|
|
|
|
gdb_byte pattern = 'x';
|
|
|
|
CORE_ADDR addr = 0;
|
|
int result = simple_search_memory (read_memory, 0, data.size (),
|
|
&pattern, 1, &addr);
|
|
/* In this case we don't care if read_fully was set or not. */
|
|
SELF_CHECK (result == 1);
|
|
SELF_CHECK (!read_off_end);
|
|
SELF_CHECK (addr == size - 1);
|
|
|
|
addr = 0;
|
|
read_fully = false;
|
|
read_off_end = false;
|
|
pattern = 'q';
|
|
result = simple_search_memory (read_memory, 0, data.size (),
|
|
&pattern, 1, &addr);
|
|
SELF_CHECK (result == 0);
|
|
SELF_CHECK (!read_off_end);
|
|
SELF_CHECK (read_fully);
|
|
SELF_CHECK (addr == 0);
|
|
|
|
/* Setup from PR gdb/17756. */
|
|
size = 0x7bb00;
|
|
data = std::vector<gdb_byte> (size);
|
|
const CORE_ADDR base_addr = 0x08370000;
|
|
const gdb_byte wpattern[] = { 0x90, 0x8b, 0x98, 0x8 };
|
|
const CORE_ADDR found_addr = 0x837bac8;
|
|
memcpy (&data[found_addr - base_addr], wpattern, sizeof (wpattern));
|
|
|
|
auto read_memory_2 = [&] (CORE_ADDR from, gdb_byte *out, size_t len)
|
|
{
|
|
memcpy (out, &data[from - base_addr], len);
|
|
return true;
|
|
};
|
|
|
|
result = simple_search_memory (read_memory_2, base_addr, data.size (),
|
|
wpattern, sizeof (wpattern), &addr);
|
|
SELF_CHECK (result == 1);
|
|
SELF_CHECK (addr == found_addr);
|
|
}
|
|
|
|
} /* namespace search_memory_tests */
|
|
} /* namespace selftests */
|
|
|
|
|
|
void _initialize_search_memory_selftests ();
|
|
void
|
|
_initialize_search_memory_selftests ()
|
|
{
|
|
selftests::register_test ("search_memory",
|
|
selftests::search_memory_tests::run_tests);
|
|
}
|