Rizin
unix-like reverse engineering framework and cli tools
libqnxr.h File Reference
#include <stdint.h>
#include <unistd.h>
#include "arch.h"
#include "rz_types_base.h"
#include "rz_socket.h"
#include "dsmsgs.h"

Go to the source code of this file.

Classes

struct  ptid_t
 
struct  libqnxr_t
 

Macros

#define MSG_OK   0
 
#define MSG_NOT_SUPPORTED   -1
 
#define MSG_ERROR_1   -2
 
#define X86_64   ARCH_X86_64
 
#define X86_32   ARCH_X86_32
 
#define ARM_32   ARCH_ARM_32
 
#define ARM_64   ARCH_ARM_64
 

Typedefs

typedef struct libqnxr_t libqnxr_t
 
typedef void() pidlist_cb_t(void *ctx, pid_t pid, char *name)
 

Functions

int qnxr_init (libqnxr_t *g)
 
int qnxr_set_architecture (libqnxr_t *g, ut8 architecture)
 
int qnxr_cleanup (libqnxr_t *g)
 
int qnxr_connect (libqnxr_t *g, const char *server, int port)
 
int qnxr_disconnect (libqnxr_t *g)
 
void qnxr_pidlist (libqnxr_t *g, void *ctx, pidlist_cb_t *cb)
 
int qnxr_select (libqnxr_t *g, pid_t pid, int tid)
 
ptid_t qnxr_run (libqnxr_t *g, const char *file, char **args, char **env)
 
ptid_t qnxr_attach (libqnxr_t *g, pid_t pid)
 
ptid_t qnxr_wait (libqnxr_t *g, pid_t pid)
 
int qnxr_stop (libqnxr_t *g)
 
int qnxr_continue (libqnxr_t *g, int thread_id)
 
int qnxr_step (libqnxr_t *g, int thread_id)
 
int qnxr_read_registers (libqnxr_t *g)
 
int qnxr_write_reg (libqnxr_t *g, const char *name, char *value, int len)
 
int qnxr_write_register (libqnxr_t *g, int index, char *value, int len)
 
int qnxr_read_memory (libqnxr_t *g, ut64 address, ut8 *data, ut64 len)
 
int qnxr_write_memory (libqnxr_t *g, ut64 address, const ut8 *data, ut64 len)
 
int qnxr_set_bp (libqnxr_t *g, ut64 address, const char *conditions)
 
int qnxr_set_hwbp (libqnxr_t *g, ut64 address, const char *conditions)
 
int qnxr_remove_bp (libqnxr_t *g, ut64 address)
 
int qnxr_remove_hwbp (libqnxr_t *g, ut64 address)
 
int ptid_equal (ptid_t ptid1, ptid_t ptid2)
 

Variables

ptid_t null_ptid
 

Macro Definition Documentation

◆ ARM_32

#define ARM_32   ARCH_ARM_32

Definition at line 26 of file libqnxr.h.

◆ ARM_64

#define ARM_64   ARCH_ARM_64

Definition at line 27 of file libqnxr.h.

◆ MSG_ERROR_1

#define MSG_ERROR_1   -2

Definition at line 22 of file libqnxr.h.

◆ MSG_NOT_SUPPORTED

#define MSG_NOT_SUPPORTED   -1

Definition at line 21 of file libqnxr.h.

◆ MSG_OK

#define MSG_OK   0

Definition at line 20 of file libqnxr.h.

◆ X86_32

#define X86_32   ARCH_X86_32

Definition at line 25 of file libqnxr.h.

◆ X86_64

#define X86_64   ARCH_X86_64

Definition at line 24 of file libqnxr.h.

Typedef Documentation

◆ libqnxr_t

typedef struct libqnxr_t libqnxr_t

Core "object" that saves the instance of the lib

◆ pidlist_cb_t

typedef void() pidlist_cb_t(void *ctx, pid_t pid, char *name)

Definition at line 69 of file libqnxr.h.

Function Documentation

◆ ptid_equal()

int ptid_equal ( ptid_t  ptid1,
ptid_t  ptid2 
)

Definition at line 309 of file utils.c.

309  {
310  return ptid1.pid == ptid2.pid && ptid1.tid == ptid2.tid;
311 }
st32 pid
Definition: libqnxr.h:31
st64 tid
Definition: libqnxr.h:32

References ptid_t::pid, and ptid_t::tid.

Referenced by rz_debug_qnx_wait().

◆ qnxr_attach()

ptid_t qnxr_attach ( libqnxr_t g,
pid_t  pid 
)

Definition at line 223 of file core.c.

223  {
224 
225  if (g->inferior_ptid.pid != pid) {
227  rz_sys_sleep(1);
228  qnxr_connect(g, g->host, g->port);
229  }
230 
232  g->tran.pkt.attach.pid = pid;
233  g->tran.pkt.attach.pid = EXTRACT_SIGNED_INTEGER(&g->tran.pkt.attach.pid, 4);
234 
235  nto_send(g, sizeof(g->tran.pkt.attach), 0);
236  if (g->recv.pkt.hdr.cmd != DSrMsg_okdata) {
237  eprintf("%s: failed to attach to %d\n", __func__, pid);
238  return null_ptid;
239  }
240 
241  g->inferior_ptid = ptid_build(
242  EXTRACT_SIGNED_INTEGER(&g->recv.pkt.notify.pid, 4),
243  EXTRACT_SIGNED_INTEGER(&g->recv.pkt.notify.tid, 4));
244 
245  return g->inferior_ptid;
246 }
#define SET_CHANNEL_DEBUG
Definition: dsmsgs.h:94
@ DStMsg_attach
Definition: dsmsgs.h:128
@ DSrMsg_okdata
Definition: dsmsgs.h:155
struct @667 g
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc pid
Definition: sflib.h:64
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API int rz_sys_sleep(int secs)
Sleep for secs seconds.
Definition: sys.c:300
ptid_t ptid_build(st32 pid, st64 tid)
Definition: utils.c:301
#define EXTRACT_SIGNED_INTEGER(addr, len)
Definition: utils.h:20
int qnxr_connect(libqnxr_t *g, const char *host, int port)
Definition: core.c:147
void nto_send_init(libqnxr_t *g, ut32 cmd, ut32 subcmd, ut32 chan)
Definition: core.c:643
int qnxr_disconnect(libqnxr_t *g)
Definition: core.c:206
int nto_send(libqnxr_t *g, ut32 len, int report_errors)
ptid_t null_ptid
Definition: core.c:18

References DSrMsg_okdata, DStMsg_attach, eprintf, EXTRACT_SIGNED_INTEGER, g, nto_send(), nto_send_init(), null_ptid, pid, ptid_build(), qnxr_connect(), qnxr_disconnect(), rz_sys_sleep(), and SET_CHANNEL_DEBUG.

Referenced by rz_debug_qnx_attach().

◆ qnxr_cleanup()

int qnxr_cleanup ( libqnxr_t g)

Definition at line 138 of file core.c.

138  {
139  if (!g)
140  return -1;
141  free(g->send_buff);
142  g->send_len = 0;
143  free(g->read_buff);
144  return 0;
145 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130

References free(), and g.

◆ qnxr_connect()

int qnxr_connect ( libqnxr_t g,
const char *  server,
int  port 
)

Definition at line 147 of file core.c.

147  {
148  char tmp[255];
149  int ret;
150  if (!g || !host || g->connected)
151  return -1;
152 
153  g->data_len = 0;
154  g->read_len = 0;
155  g->read_ptr = 0;
156  g->sock = rz_socket_new(0);
157  g->connected = 0;
158  g->mid = 0;
159 
160  memmove(g->host, host, strlen(host) + 1);
161  g->port = port;
162 
163  ret = snprintf(tmp, sizeof(tmp) - 1, "%d", port);
164  if (!ret)
165  return -1;
166  ret = rz_socket_connect_tcp(g->sock, host, tmp, 200);
167  if (!ret)
168  return -1;
169  g->connected = 1;
170 
173  g->tran.pkt.connect.major = HOST_QNX_PROTOVER_MAJOR;
174  g->tran.pkt.connect.minor = HOST_QNX_PROTOVER_MINOR;
175  nto_send(g, sizeof(g->tran.pkt.connect), 0);
176 
177  if (g->recv.pkt.hdr.cmd == DSrMsg_err) {
178  eprintf("%s: connection failed: %lld\n", __func__,
179  EXTRACT_SIGNED_INTEGER(&g->recv.pkt.err.err, 4));
180  return -1;
181  }
182 
183  /* Try to query pdebug for their version of the protocol */
185  g->tran.pkt.protover.major = HOST_QNX_PROTOVER_MAJOR;
186  g->tran.pkt.protover.minor = HOST_QNX_PROTOVER_MINOR;
187  nto_send(g, sizeof(g->tran.pkt.protover), 0);
188 
189  if ((g->recv.pkt.hdr.cmd == DSrMsg_err) && (EXTRACT_SIGNED_INTEGER(&g->recv.pkt.err.err, 4) == EINVAL)) {
190  g->target_proto_major = 0;
191  g->target_proto_minor = 0;
192  } else if (g->recv.pkt.hdr.cmd == DSrMsg_okstatus) {
193  g->target_proto_major = EXTRACT_SIGNED_INTEGER(&g->recv.pkt.okstatus.status, 4);
194  g->target_proto_minor = EXTRACT_SIGNED_INTEGER(&g->recv.pkt.okstatus.status, 4);
195  g->target_proto_major = (g->target_proto_major >> 8) & DSMSG_PROTOVER_MAJOR;
196  g->target_proto_minor = g->target_proto_minor & DSMSG_PROTOVER_MINOR;
197  } else {
198  eprintf("Connection failed (Protocol Version Query): %lld\n",
199  EXTRACT_SIGNED_INTEGER(&g->recv.pkt.err.err, 4));
200  return -1;
201  }
202 
203  return 0;
204 }
@ DSrMsg_err
Definition: dsmsgs.h:152
@ DSrMsg_okstatus
Definition: dsmsgs.h:154
@ DStMsg_protover
Definition: dsmsgs.h:146
@ DStMsg_connect
Definition: dsmsgs.h:123
@ DSMSG_PROTOVER_MAJOR
Definition: dsmsgs.h:227
@ DSMSG_PROTOVER_MINOR
Definition: dsmsgs.h:225
snprintf
Definition: kernel.h:364
#define rz_socket_connect_tcp(a, b, c, d)
Definition: rz_socket.h:99
RZ_API RzSocket * rz_socket_new(bool is_ssl)
Definition: socket.c:179
int qnxr_send_ch_reset(libqnxr_t *instance)
Definition: packet.c:131
#define EINVAL
Definition: sftypes.h:132
#define HOST_QNX_PROTOVER_MINOR
Definition: core.c:16
#define HOST_QNX_PROTOVER_MAJOR
Definition: core.c:15

References DSMSG_PROTOVER_MAJOR, DSMSG_PROTOVER_MINOR, DSrMsg_err, DSrMsg_okstatus, DStMsg_connect, DStMsg_protover, EINVAL, eprintf, EXTRACT_SIGNED_INTEGER, g, HOST_QNX_PROTOVER_MAJOR, HOST_QNX_PROTOVER_MINOR, nto_send(), nto_send_init(), qnxr_send_ch_reset(), rz_socket_connect_tcp, rz_socket_new(), SET_CHANNEL_DEBUG, snprintf, and autogen_x86imm::tmp.

Referenced by __open(), and qnxr_attach().

◆ qnxr_continue()

int qnxr_continue ( libqnxr_t g,
int  thread_id 
)

Definition at line 470 of file core.c.

470  {
471  return qnxr_send_vcont(g, 0, thread_id);
472 }
int qnxr_send_vcont(libqnxr_t *g, int step, int thread_id)
Definition: core.c:517

References g, and qnxr_send_vcont().

Referenced by rz_debug_qnx_continue().

◆ qnxr_disconnect()

int qnxr_disconnect ( libqnxr_t g)

Definition at line 206 of file core.c.

206  {
207  if (!g)
208  return -1;
209 
210  if (g->connected) {
212  nto_send(g, sizeof(g->tran.pkt.disconnect), 0);
213  g->connected = 0;
214  g->inferior_ptid = null_ptid;
215 
216  if (!rz_socket_close(g->sock))
217  return -1;
218  }
219 
220  return 0;
221 }
@ DStMsg_disconnect
Definition: dsmsgs.h:124
RZ_API int rz_socket_close(RzSocket *s)
Definition: socket.c:419

References DStMsg_disconnect, g, nto_send(), nto_send_init(), null_ptid, rz_socket_close(), and SET_CHANNEL_DEBUG.

Referenced by qnxr_attach(), and rz_debug_qnx_detach().

◆ qnxr_init()

int qnxr_init ( libqnxr_t g)

Definition at line 104 of file core.c.

104  {
105  if (!g)
106  return -1;
107  memset(g, 0, sizeof(libqnxr_t));
108  g->send_len = 0;
109  g->send_buff = (char *)calloc(DS_DATA_MAX_SIZE * 2, 1);
110  if (!g->send_buff)
111  return -1;
112  g->read_buff = (char *)calloc(DS_DATA_MAX_SIZE * 2, 1);
113  if (!g->read_buff) {
114  RZ_FREE(g->send_buff);
115  return -1;
116  }
117  g->registers = x86_32;
118  return 0;
119 }
#define DS_DATA_MAX_SIZE
Definition: dsmsgs.h:102
return memset(p, 0, total)
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
#define RZ_FREE(x)
Definition: rz_types.h:369
static registers_t x86_32[]
Definition: core.c:27

References calloc(), DS_DATA_MAX_SIZE, g, memset(), RZ_FREE, and x86_32.

Referenced by __open().

◆ qnxr_pidlist()

void qnxr_pidlist ( libqnxr_t g,
void *  ctx,
pidlist_cb_t cb 
)

Definition at line 417 of file core.c.

417  {
418  struct dspidlist *pidlist = (void *)g->recv.pkt.okdata.data;
419  pid_t pid, start_tid;
420  char subcmd;
421 
422  if (!g)
423  return;
424 
425  start_tid = 1;
426  pid = 1;
427  subcmd = DSMSG_PIDLIST_BEGIN;
428 
429  while (1) {
431  g->tran.pkt.pidlist.pid = EXTRACT_SIGNED_INTEGER(&pid, 4);
432  g->tran.pkt.pidlist.tid = EXTRACT_SIGNED_INTEGER(&start_tid, 4);
433  nto_send(g, sizeof(g->tran.pkt.pidlist), 0);
434 
435  if (g->recv.pkt.hdr.cmd == DSrMsg_err || g->recv.pkt.hdr.cmd != DSrMsg_okdata)
436  return;
437 
438  pid = EXTRACT_SIGNED_INTEGER(&pidlist->pid, 4);
439  if (cb != NULL)
440  cb(ctx, pid, pidlist->name);
441  subcmd = DSMSG_PIDLIST_NEXT;
442  }
443 }
#define NULL
Definition: cris-opc.c:27
@ DSMSG_PIDLIST_NEXT
Definition: dsmsgs.h:207
@ DSMSG_PIDLIST_BEGIN
Definition: dsmsgs.h:206
@ DStMsg_pidlist
Definition: dsmsgs.h:142
int pid_t
Definition: sftypes.h:38
char name[1]
Definition: dsmsgs.h:538
st32 pid
Definition: dsmsgs.h:530
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4
static const char * cb[]
Definition: z80_tab.h:176

References cb, DSMSG_PIDLIST_BEGIN, DSMSG_PIDLIST_NEXT, DSrMsg_err, DSrMsg_okdata, DStMsg_pidlist, EXTRACT_SIGNED_INTEGER, g, if(), dspidlist::name, nto_send(), nto_send_init(), NULL, pid, dspidlist::pid, and SET_CHANNEL_DEBUG.

Referenced by rz_debug_qnx_pids().

◆ qnxr_read_memory()

int qnxr_read_memory ( libqnxr_t g,
ut64  address,
ut8 data,
ut64  len 
)

Definition at line 365 of file core.c.

365  {
366  int rcv_len, tot_len, ask_len;
367  ut64 addr;
368 
369  if (!g || !data)
370  return -1;
371 
372  tot_len = ask_len = 0;
373 
374  do {
376  addr = address + tot_len;
377  g->tran.pkt.memrd.addr = EXTRACT_UNSIGNED_INTEGER(&addr, 8);
378  ask_len = ((len - tot_len) > DS_DATA_MAX_SIZE) ? DS_DATA_MAX_SIZE : (len - tot_len);
379 
380  g->tran.pkt.memrd.size = EXTRACT_SIGNED_INTEGER(&ask_len, 2);
381  rcv_len = nto_send(g, sizeof(g->tran.pkt.memrd), 0) -
382  sizeof(g->recv.pkt.hdr);
383  if (rcv_len <= 0)
384  break;
385  if (g->recv.pkt.hdr.cmd == DSrMsg_okdata) {
386  memcpy(data + tot_len, g->recv.pkt.okdata.data, rcv_len);
387  tot_len += rcv_len;
388  } else
389  break;
390  } while (tot_len != len);
391 
392  return tot_len;
393 }
size_t len
Definition: 6502dis.c:15
@ DStMsg_memrd
Definition: dsmsgs.h:132
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
#define EXTRACT_UNSIGNED_INTEGER(addr, len)
Definition: utils.h:22
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58

References addr, DS_DATA_MAX_SIZE, DSrMsg_okdata, DStMsg_memrd, EXTRACT_SIGNED_INTEGER, EXTRACT_UNSIGNED_INTEGER, g, len, memcpy(), nto_send(), nto_send_init(), SET_CHANNEL_DEBUG, and ut64().

Referenced by debug_qnx_read_at().

◆ qnxr_read_registers()

int qnxr_read_registers ( libqnxr_t g)

Definition at line 323 of file core.c.

323  {
324  int i = 0;
325  int len, rlen, regset;
326  int n = 0;
327  ut32 off;
328  char buf[DS_DATA_MAX_SIZE];
329 
330  if (!g)
331  return -1;
332 
333  while (g->registers[i].size > 0) {
334  regset = i386nto_regset_id(i);
335  len = i386nto_register_area(i, regset, &off);
336  if (len < 1) {
337  eprintf("%s: unknown register %d\n", __func__, i);
338  len = g->registers[i].size;
339  }
341  g->tran.pkt.regrd.offset = EXTRACT_SIGNED_INTEGER(&off, 2);
342  g->tran.pkt.regrd.size = EXTRACT_SIGNED_INTEGER(&len, 2);
343  rlen = nto_send(g, sizeof(g->tran.pkt.regrd), 1);
344 
345  if (rlen > 0) {
346  if (g->recv.pkt.hdr.cmd == DSrMsg_okdata) {
347  memcpy(buf + g->registers[i].offset,
348  g->recv.pkt.okdata.data, len);
349  n += len;
350  } else {
351  memset(buf + g->registers[i].offset,
352  0, len);
353  }
354  } else {
355  eprintf("%s: couldn't read register %d\n", __func__, i);
356  return -1;
357  }
358  i++;
359  }
360 
361  memcpy(g->recv.data, buf, n);
362  return n;
363 }
lzma_index ** i
Definition: index.h:629
uint32_t ut32
@ DStMsg_regrd
Definition: dsmsgs.h:134
voidpf void * buf
Definition: ioapi.h:138
int n
Definition: mipsasm.c:19
int off
Definition: pal.c:13
int i386nto_regset_id(int regno)
Definition: utils.c:191
int i386nto_register_area(int regno, int regset, unsigned *off)

References DS_DATA_MAX_SIZE, DSrMsg_okdata, DStMsg_regrd, eprintf, EXTRACT_SIGNED_INTEGER, g, i, i386nto_register_area(), i386nto_regset_id(), len, memcpy(), memset(), n, nto_send(), nto_send_init(), off, and SET_CHANNEL_DEBUG.

Referenced by rz_debug_qnx_reg_read().

◆ qnxr_remove_bp()

int qnxr_remove_bp ( libqnxr_t g,
ut64  address 
)

Definition at line 607 of file core.c.

607  {
608  return _qnxr_remove_bp(g, address, BREAKPOINT);
609 }
@ BREAKPOINT
Definition: core.h:47
int _qnxr_remove_bp(libqnxr_t *g, ut64 address, enum Breakpoint type)
Definition: core.c:629

References _qnxr_remove_bp(), BREAKPOINT, and g.

Referenced by rz_debug_qnx_breakpoint().

◆ qnxr_remove_hwbp()

int qnxr_remove_hwbp ( libqnxr_t g,
ut64  address 
)

Definition at line 611 of file core.c.

611  {
612  return _qnxr_remove_bp(g, address, HARDWARE_BREAKPOINT);
613 }
@ HARDWARE_BREAKPOINT
Definition: core.h:48

References _qnxr_remove_bp(), g, and HARDWARE_BREAKPOINT.

Referenced by rz_debug_qnx_breakpoint().

◆ qnxr_run()

ptid_t qnxr_run ( libqnxr_t g,
const char *  file,
char **  args,
char **  env 
)

Definition at line 248 of file core.c.

248  {
249  ut32 argc = 0;
250  ut32 envc = 0;
251 
252  char **argv, *p;
253  int errors = 0;
254 
255  if (!g)
256  return null_ptid;
257 
259  nto_send(g, sizeof(DStMsg_env_t), 1);
260 
261  for (envc = 0; *env; env++, envc++)
262  errors += !nto_send_env(g, *env);
263 
264  if (errors) {
265  eprintf("%s: error(s) occurred while sending environment\n", __func__);
266  }
267 
269  nto_send(g, sizeof(DStMsg_env_t), 1);
270 
271  if (file != NULL) {
272  errors = !nto_send_arg(g, file);
273  if (!errors)
274  errors = !nto_send_arg(g, file);
275 
276  if (errors) {
277  eprintf("%s: failed to send executable file name\n", __func__);
278  return null_ptid;
279  }
280 
281  errors = 0;
282  for (argv = args; *argv && **argv; argv++, argc++)
283  errors |= !nto_send_arg(g, *argv);
284 
285  if (errors) {
286  eprintf("%s: error(s) occurred while sending args\n", __func__);
287  }
288  }
289 
290  if (errors) {
291  return null_ptid;
292  }
293 
295  p = g->tran.pkt.load.cmdline;
296 
297  g->tran.pkt.load.envc = 0;
298  g->tran.pkt.load.argc = 0;
299 
300  if (file) {
301  strncpy(p, file, sizeof(g->tran.pkt.load.cmdline) - 8);
302  p += strlen(p);
303  }
304  *p++ = '\0';
305 
306  *p++ = '\0'; // stdin
307  *p++ = '\0'; // stdout
308  *p++ = '\0'; // stderr
309 
310  nto_send(g, offsetof(DStMsg_load_t, cmdline) + p - g->tran.pkt.load.cmdline + 1, 1);
311 
312  if (g->recv.pkt.hdr.cmd == DSrMsg_okdata) {
313  ptid_t ptid = nto_parse_notify(g);
314  eprintf("%s: inferior pid: %d\n", __func__, ptid.pid);
315  g->inferior_ptid = ptid;
316 
317  return ptid;
318  }
319 
320  return null_ptid;
321 }
@ DSMSG_ENV_CLEARENV
Definition: dsmsgs.h:171
@ DSMSG_ENV_CLEARARGV
Definition: dsmsgs.h:169
@ DSMSG_LOAD_DEBUG
Definition: dsmsgs.h:162
@ DStMsg_env
Definition: dsmsgs.h:144
@ DStMsg_load
Definition: dsmsgs.h:127
#define offsetof(type, member)
void * p
Definition: libc.cpp:67
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
int args
Definition: mipsasm.c:18
Definition: gzappend.c:170
Definition: libqnxr.h:30
int nto_send_env(libqnxr_t *g, const char *env)
Definition: core.c:699
int nto_send_arg(libqnxr_t *g, const char *arg)
Definition: core.c:732
ptid_t nto_parse_notify(libqnxr_t *g)
Definition: core.c:650
static char ** env
Definition: sys.c:32

References args, argv, DSMSG_ENV_CLEARARGV, DSMSG_ENV_CLEARENV, DSMSG_LOAD_DEBUG, DSrMsg_okdata, DStMsg_env, DStMsg_load, env, eprintf, g, nto_parse_notify(), nto_send(), nto_send_arg(), nto_send_env(), nto_send_init(), NULL, null_ptid, offsetof, p, ptid_t::pid, and SET_CHANNEL_DEBUG.

◆ qnxr_select()

int qnxr_select ( libqnxr_t g,
pid_t  pid,
int  tid 
)

Definition at line 445 of file core.c.

445  {
446  if (!g)
447  return 0;
448 
449  /* TODO */
450  tid = 1;
451 
453  g->tran.pkt.select.pid = pid;
454  g->tran.pkt.select.pid = EXTRACT_SIGNED_INTEGER(&g->tran.pkt.select.pid, 4);
455  g->tran.pkt.select.tid = EXTRACT_SIGNED_INTEGER(&tid, 4);
456  nto_send(g, sizeof(g->tran.pkt.select), 1);
457 
458  if (g->recv.pkt.hdr.cmd == DSrMsg_err) {
459  eprintf("%s: failed to select %d\n", __func__, pid);
460  return 0;
461  }
462 
463  return 1;
464 }
@ DSMSG_SELECT_SET
Definition: dsmsgs.h:179
@ DStMsg_select
Definition: dsmsgs.h:125

References DSMSG_SELECT_SET, DSrMsg_err, DStMsg_select, eprintf, EXTRACT_SIGNED_INTEGER, g, nto_send(), nto_send_init(), pid, and SET_CHANNEL_DEBUG.

Referenced by rz_debug_qnx_select().

◆ qnxr_set_architecture()

int qnxr_set_architecture ( libqnxr_t g,
ut8  architecture 
)

Definition at line 121 of file core.c.

121  {
122  if (!g)
123  return -1;
124  g->architecture = architecture;
125  switch (architecture) {
126  case ARCH_X86_32:
127  g->registers = x86_32;
128  break;
129  case ARCH_ARM_32:
130  g->registers = arm32;
131  break;
132  default:
133  eprintf("Error unknown architecture set\n");
134  }
135  return 0;
136 }
#define ARCH_ARM_32
Definition: arch.h:12
#define ARCH_X86_32
Definition: arch.h:11
static registers_t arm32[]
Definition: core.c:74

References ARCH_ARM_32, ARCH_X86_32, arm32, eprintf, g, and x86_32.

Referenced by rz_debug_qnx_attach().

◆ qnxr_set_bp()

int qnxr_set_bp ( libqnxr_t g,
ut64  address,
const char *  conditions 
)

Definition at line 599 of file core.c.

599  {
600  return _qnxr_set_bp(g, address, conditions, BREAKPOINT);
601 }
static const char * conditions[]
int _qnxr_set_bp(libqnxr_t *g, ut64 address, const char *conditions, enum Breakpoint type)
Definition: core.c:615

References _qnxr_set_bp(), BREAKPOINT, conditions, and g.

Referenced by rz_debug_qnx_breakpoint().

◆ qnxr_set_hwbp()

int qnxr_set_hwbp ( libqnxr_t g,
ut64  address,
const char *  conditions 
)

Definition at line 603 of file core.c.

603  {
604  return _qnxr_set_bp(g, address, conditions, HARDWARE_BREAKPOINT);
605 }

References _qnxr_set_bp(), conditions, g, and HARDWARE_BREAKPOINT.

Referenced by rz_debug_qnx_breakpoint().

◆ qnxr_step()

int qnxr_step ( libqnxr_t g,
int  thread_id 
)

Definition at line 466 of file core.c.

466  {
467  return qnxr_send_vcont(g, 1, thread_id);
468 }

References g, and qnxr_send_vcont().

Referenced by rz_debug_qnx_step().

◆ qnxr_stop()

int qnxr_stop ( libqnxr_t g)

Definition at line 528 of file core.c.

528  {
529  if (!g)
530  return 0;
531 
532  eprintf("%s: waiting for stop\n", __func__);
533  g->waiting_for_stop = 1;
535 
536  g->send_len = sizeof(g->tran.pkt.stop);
538 
539  return 1;
540 }
@ DSMSG_STOP_PIDS
Definition: dsmsgs.h:177
@ DStMsg_stop
Definition: dsmsgs.h:131
int qnxr_send_packet(libqnxr_t *instance)
sends a packet sends a packet to the established connection
Definition: packet.c:143

References DSMSG_STOP_PIDS, DStMsg_stop, eprintf, g, nto_send_init(), qnxr_send_packet(), and SET_CHANNEL_DEBUG.

Referenced by rz_debug_qnx_stop().

◆ qnxr_wait()

ptid_t qnxr_wait ( libqnxr_t g,
pid_t  pid 
)

Definition at line 542 of file core.c.

542  {
543  if (!g || pid < 0) {
544  return null_ptid;
545  }
546  ptid_t returned_ptid = g->inferior_ptid;
547  if (g->inferior_ptid.pid != pid) {
548  return null_ptid;
549  }
550  if (g->recv.pkt.hdr.cmd != DShMsg_notify) {
551  int rlen;
552  char waiting_for_notify = 1;
553 
554  eprintf("%s: waiting for inferior\n", __func__);
555 
556  while (1) {
557  rlen = qnxr_read_packet(g);
558  if (rlen == -1) {
559  if (g->waiting_for_stop) {
560  eprintf("%s: read eror while waiting for stop\n",
561  __func__);
562  continue;
563  } else {
564  eprintf("%s: read packet error or NAK\n", __func__);
565  return null_ptid;
566  }
567  }
568  if (g->channelrd == SET_CHANNEL_TEXT) {
569  // TODO nto_incoming_text
570  } else {
571  g->recv.pkt.hdr.cmd &= ~DSHDR_MSG_BIG_ENDIAN;
572  if (g->waiting_for_stop && g->recv.pkt.hdr.cmd == DSrMsg_ok) {
573  g->waiting_for_stop = 0;
574  eprintf("%s: got stop response\n", __func__);
575  if (!waiting_for_notify)
576  break;
577  } else if (g->recv.pkt.hdr.cmd == DShMsg_notify) {
578  // acknowledge the notify
579  g->tran.pkt.hdr.cmd = DSrMsg_ok;
580  g->tran.pkt.hdr.channel = SET_CHANNEL_DEBUG;
581  g->tran.pkt.hdr.mid = g->recv.pkt.hdr.mid;
583 
584  g->send_len = sizeof(g->tran.pkt.ok);
586 
587  returned_ptid = nto_parse_notify(g);
588  break;
589  }
590  }
591  }
592  }
593 
594  /* to make us wait the next time */
595  g->recv.pkt.hdr.cmd = DSrMsg_ok;
596  return returned_ptid;
597 }
#define DSHDR_MSG_BIG_ENDIAN
Definition: dsmsgs.h:113
#define SET_CHANNEL_TEXT
Definition: dsmsgs.h:95
@ DShMsg_notify
Definition: dsmsgs.h:157
@ DSrMsg_ok
Definition: dsmsgs.h:153
int qnxr_send_ch_debug(libqnxr_t *instance)
Definition: packet.c:135
int qnxr_read_packet(libqnxr_t *instance)
Function reads data from the established connection.
Definition: packet.c:65

References DSHDR_MSG_BIG_ENDIAN, DShMsg_notify, DSrMsg_ok, eprintf, g, nto_parse_notify(), null_ptid, pid, qnxr_read_packet(), qnxr_send_ch_debug(), qnxr_send_packet(), SET_CHANNEL_DEBUG, and SET_CHANNEL_TEXT.

Referenced by rz_debug_qnx_wait().

◆ qnxr_write_memory()

int qnxr_write_memory ( libqnxr_t g,
ut64  address,
const ut8 data,
ut64  len 
)

Definition at line 395 of file core.c.

395  {
396  ut64 addr;
397 
398  if (!g || !data)
399  return -1;
400 
402  addr = address;
403  g->tran.pkt.memwr.addr = EXTRACT_UNSIGNED_INTEGER(&addr, 8);
404  memcpy(g->tran.pkt.memwr.data, data, len);
405  nto_send(g, offsetof(DStMsg_memwr_t, data) + len, 0);
406 
407  switch (g->recv.pkt.hdr.cmd) {
408  case DSrMsg_ok:
409  return len;
410  case DSrMsg_okstatus:
411  return EXTRACT_SIGNED_INTEGER(&g->recv.pkt.okstatus.status, 4);
412  }
413 
414  return 0;
415 }
@ DStMsg_memwr
Definition: dsmsgs.h:133

References addr, DSrMsg_ok, DSrMsg_okstatus, DStMsg_memwr, EXTRACT_SIGNED_INTEGER, EXTRACT_UNSIGNED_INTEGER, g, len, memcpy(), nto_send(), nto_send_init(), offsetof, SET_CHANNEL_DEBUG, and ut64().

Referenced by debug_qnx_write_at().

◆ qnxr_write_reg()

int qnxr_write_reg ( libqnxr_t g,
const char *  name,
char *  value,
int  len 
)

Definition at line 496 of file core.c.

496  {
497  int i = 0;
498 
499  if (!g)
500  return -1;
501 
502  while (g->registers[i].size > 0) {
503  if (!strcmp(g->registers[i].name, name)) {
504  break;
505  }
506  i++;
507  }
508  if (g->registers[i].size == 0) {
509  eprintf("Error registername <%s> not found in profile\n", name);
510  return -1;
511  }
513 
514  return 0;
515 }
static int value
Definition: cmd_api.c:93
Definition: z80asm.h:102
int qnxr_write_register(libqnxr_t *g, int index, char *value, int len)
Definition: core.c:474

References eprintf, g, i, len, qnxr_write_register(), and value.

Referenced by rz_debug_qnx_reg_write().

◆ qnxr_write_register()

int qnxr_write_register ( libqnxr_t g,
int  index,
char *  value,
int  len 
)

Definition at line 474 of file core.c.

474  {
475  int tdep_len, regset;
476  ut32 off;
477 
478  if (!g)
479  return -1;
480 
481  regset = i386nto_regset_id(index);
482  tdep_len = i386nto_register_area(index, regset, &off);
483  if (len < 0 || tdep_len != len) {
484  eprintf("%s: invalid length\n", __func__);
485  return -1;
486  }
487 
489  g->tran.pkt.regwr.offset = EXTRACT_SIGNED_INTEGER(&off, 2);
490  memcpy(g->tran.pkt.regwr.data, value, len);
491  nto_send(g, offsetof(DStMsg_regwr_t, data) + len, 1);
492 
493  return 0;
494 }
@ DStMsg_regwr
Definition: dsmsgs.h:135

References DStMsg_regwr, eprintf, EXTRACT_SIGNED_INTEGER, g, i386nto_register_area(), i386nto_regset_id(), len, memcpy(), nto_send(), nto_send_init(), off, offsetof, SET_CHANNEL_DEBUG, and value.

Referenced by qnxr_write_reg().

Variable Documentation

◆ null_ptid

ptid_t null_ptid
extern

Definition at line 18 of file core.c.

Referenced by qnxr_attach(), qnxr_disconnect(), qnxr_run(), qnxr_wait(), and rz_debug_qnx_wait().