diff options
Diffstat (limited to 'agent/tcf/main')
-rw-r--r-- | agent/tcf/main/gdb-rsp.c | 104 | ||||
-rw-r--r-- | agent/tcf/main/logfilter.c | 8 | ||||
-rw-r--r-- | agent/tcf/main/main.c | 2 | ||||
-rw-r--r-- | agent/tcf/main/main_lua.c | 6 | ||||
-rw-r--r-- | agent/tcf/main/tcf-agent.spec | 2 |
5 files changed, 83 insertions, 39 deletions
diff --git a/agent/tcf/main/gdb-rsp.c b/agent/tcf/main/gdb-rsp.c index 5335deb2..9c4fcad6 100644 --- a/agent/tcf/main/gdb-rsp.c +++ b/agent/tcf/main/gdb-rsp.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016-2020 Xilinx, Inc. and others. + * Copyright (c) 2016-2022 Xilinx, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * and Eclipse Distribution License v1.0 which accompany this distribution. @@ -60,7 +60,7 @@ # define DEBUG_RSP 0 #endif -#define ID_ANY ~0u +#define ID_ALL ~0u typedef struct GdbServer { LINK link_a2s; @@ -78,7 +78,7 @@ typedef struct GdbClient { uint8_t * buf; AsyncReqInfo req; GdbServer * server; - ClientConnection client; + ClientConnection connection; int closed; /* Command packet */ @@ -161,7 +161,7 @@ typedef struct MonitorCommand { #define link_p2t(x) ((GdbThread *)((char *)(x) - offsetof(GdbThread, link_p2t))) #define link_p2b(x) ((GdbBreakpoint *)((char *)(x) - offsetof(GdbBreakpoint, link_p2b))) -#define client2gdb(c) ((GdbClient *)((char *)(c) - offsetof(GdbClient, client))) +#define client2gdb(c) ((GdbClient *)((char *)(c) - offsetof(GdbClient, connection))) static int ini_done = 0; static LINK link_a2s; @@ -321,9 +321,18 @@ static unsigned reg_name_hash(const char * name) { return h; } -static RegisterDefinition * find_register(GdbThread * t, GdbRegister * r) { +static RegisterDefinition * find_register_by_name(GdbThread * t, const char * name) { RegisterDefinition ** map = t->regs_nm_map; - unsigned n = 0; + unsigned n = reg_name_hash(name) & t->regs_nm_map_index_mask; + while (map[n] != NULL) { + if (strcmp(map[n]->name, name) == 0) return map[n]; + n = (n + 1) & t->regs_nm_map_index_mask; + } + return NULL; +} + +static RegisterDefinition * find_register(GdbThread * t, GdbRegister * r) { + RegisterDefinition * res = NULL; if (r->id >= 0) { RegisterDefinition * def = get_reg_definitions(t->ctx); @@ -334,9 +343,10 @@ static RegisterDefinition * find_register(GdbThread * t, GdbRegister * r) { } return NULL; } - if (map == NULL) { + if (t->regs_nm_map == NULL) { unsigned map_len = 0; unsigned map_len_p2 = 1; + RegisterDefinition ** map = NULL; RegisterDefinition * def = get_reg_definitions(t->ctx); if (def == NULL) return NULL; while (def->name != NULL) { @@ -356,12 +366,31 @@ static RegisterDefinition * find_register(GdbThread * t, GdbRegister * r) { } t->regs_nm_map = map; } - n = reg_name_hash(r->name) & t->regs_nm_map_index_mask; - while (map[n] != NULL) { - if (strcmp(map[n]->name, r->name) == 0) return map[n]; - n = (n + 1) & t->regs_nm_map_index_mask; + res = find_register_by_name(t, r->name); + if (res == NULL) { + const char * regs = get_regs(t->process->client); + /* Try alternative register names */ + if (regs == cpu_regs_gdb_i386 || regs == cpu_regs_gdb_x86_64) { + static const char * alt_names[] = { + "fctrl", "control", "fpcr", "cwd", NULL, + "fstat", "status", "fpsr", "swd", NULL, + "ftag", "tag", "fptag", "twd", NULL, + "fiseg", "fcs", NULL, + "fioff", "fip", NULL, + "foseg", "fos", NULL, + "fooff", "foo", NULL, + NULL + }; + unsigned i = 0; + for (; alt_names[i] != NULL && res == NULL; i++) { + int b = strcmp(alt_names[i++], r->name) == 0; + for (; alt_names[i] != NULL && res == NULL; i++) { + if (b) res = find_register_by_name(t, alt_names[i]); + } + } + } } - return NULL; + return res; } static int open_server(const char * port) { @@ -534,11 +563,11 @@ static void close_client(GdbClient * c) { c->closed = 1; unlock_threads(c); closesocket(c->req.u.sio.sock); - notify_client_disconnected(&c->client); + notify_client_disconnected(&c->connection); } } -static void dispose_client(ClientConnection * cc) { +static void dispose_connection(ClientConnection * cc) { GdbClient * c = client2gdb(cc); GdbServer * s = c->server; @@ -817,28 +846,41 @@ static void get_cmd_ptid(GdbClient * c, char ** pp, unsigned * res_pid, unsigned s++; } tid = get_cmd_uint(c, &s); + /* + ID is a positive number with target-specific interpretation formatted as a big-endian hex string, + or literal '-1' to indicate all processes or threads (respectively), + or '0' to indicate an arbitrary process (keep current selection if any) + */ if (neg_pid) { - pid = ID_ANY; + pid = ID_ALL; } else if (pid == 0) { - LINK * l; - pid = 0; - for (l = c->link_c2p.next; l != &c->link_c2p; l = l->next) { - GdbProcess * p = link_c2p(l); - if (p->attached) { - pid = p->pid; - break; + if (find_process_pid(c, *res_pid)) { + pid = *res_pid; + } + else { + LINK * l; + for (l = c->link_c2p.next; l != &c->link_c2p; l = l->next) { + GdbProcess * p = link_c2p(l); + if (p->attached) { + pid = p->pid; + break; + } } } } - if (neg_tid || pid == ID_ANY) { - tid = ID_ANY; + if (neg_tid || pid == ID_ALL) { + tid = ID_ALL; } else if (tid == 0) { - GdbProcess * p = find_process_pid(c, pid); - tid = 0; - if (p != NULL && !list_is_empty(&p->link_p2t)) { - tid = link_p2t(p->link_p2t.next)->tid; + if (find_thread(c, pid, *res_tid)) { + tid = *res_tid; + } + else { + GdbProcess * p = find_process_pid(c, pid); + if (p != NULL && !list_is_empty(&p->link_p2t)) { + tid = link_p2t(p->link_p2t.next)->tid; + } } } *pp = s; @@ -1409,7 +1451,7 @@ static int handle_v_command(GdbClient * c) { s++; get_cmd_ptid(c, &s, &c->cur_g_pid, &c->cur_g_tid); } - if (c->cur_g_tid == ID_ANY) { + if (c->cur_g_tid == ID_ALL) { GdbProcess * p = find_process_pid(c, c->cur_g_pid); switch (mode) { case 'c': @@ -1774,7 +1816,7 @@ static void accept_done(void * args) { c->req.u.sio.flags = 0; list_init(&c->link_c2p); list_add_last(&c->link_s2c, &s->link_s2c); - c->client.dispose = dispose_client; + c->connection.dispose = dispose_connection; for (l = context_root.next; l != &context_root; l = l->next) { Context * ctx = ctxl2ctxp(l); @@ -1787,7 +1829,7 @@ static void accept_done(void * args) { } } - notify_client_connected(&c->client); + notify_client_connected(&c->connection); async_req_post(&s->req); if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)&opt, sizeof(opt)) < 0) { diff --git a/agent/tcf/main/logfilter.c b/agent/tcf/main/logfilter.c index 2ad42a8c..01123c9d 100644 --- a/agent/tcf/main/logfilter.c +++ b/agent/tcf/main/logfilter.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 Wind River Systems, Inc. and others. + * Copyright (c) 2014-2022 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * and Eclipse Distribution License v1.0 which accompany this distribution. @@ -201,10 +201,10 @@ int filter_is_log_filtered(Channel * src, Channel * dst, int argc, /* Need to store the token and propagate truncation size * for reply. */ - TokenFilter * tf = (TokenFilter *)loc_alloc_zero( - sizeof(TokenFilter) + strlen(argv[1])); + const size_t len = strlen(argv[1]); + TokenFilter * tf = (TokenFilter *)loc_alloc_zero(sizeof(TokenFilter) + len); tf->chan = src; - strcpy(tf->token, argv[1]); + memcpy(tf->token, argv[1], len); list_add_last(&tf->all, &token_filters); if (mf->flags & FILTER_LIMIT_REPLY) { tf->limit = mf->limit; diff --git a/agent/tcf/main/main.c b/agent/tcf/main/main.c index bbcfd73f..d9aedc76 100644 --- a/agent/tcf/main/main.c +++ b/agent/tcf/main/main.c @@ -476,7 +476,7 @@ int main(int argc, char ** argv) { for (i = 0; i < url_cnt; i++) { if (ini_server(url_arr[i], proto, bcg) < 0) { - fprintf(stderr, "Cannot create listening port: %s\n", errno_to_str(errno)); + fprintf(stderr, "Cannot create listening port %s: %s\n", url_arr[i], errno_to_str(errno)); exit(1); } } diff --git a/agent/tcf/main/main_lua.c b/agent/tcf/main/main_lua.c index 95ff7aa0..55545093 100644 --- a/agent/tcf/main/main_lua.c +++ b/agent/tcf/main/main_lua.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2017 Wind River Systems, Inc. and others. + * Copyright (c) 2007-2020 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * and Eclipse Distribution License v1.0 which accompany this distribution. @@ -51,7 +51,8 @@ extern "C" { #include <tcf/main/framework.h> static const char * progname; -static lua_State *luastate; +static lua_State * luastate; +static int LOG_LUA = 0; struct luaref { int ref; @@ -1418,6 +1419,7 @@ int main(int argc, char ** argv) { #else + LOG_LUA = add_trace_mode(0, "lua", "LUA interpreter"); progname = argv[0]; /* Parse arguments */ diff --git a/agent/tcf/main/tcf-agent.spec b/agent/tcf/main/tcf-agent.spec index 5166b4d2..e8396bf3 100644 --- a/agent/tcf/main/tcf-agent.spec +++ b/agent/tcf/main/tcf-agent.spec @@ -1,5 +1,5 @@ %define name tcf-agent -%define version 1.7.0 +%define version 1.8.0 %define release 1.%(bin/get-os-tag) %define make_options CONF=Release PATH_Plugins=/etc/tcf/plugins |