1 /* 2 * $QNXtpLicenseC: 3 * Copyright 2005, QNX Software Systems. All Rights Reserved. 4 * 5 * This source code may contain confidential information of QNX Software 6 * Systems (QSS) and its licensors. Any use, reproduction, modification, 7 * disclosure, distribution or transfer of this software, or any software 8 * that includes or is based upon any of this code, is prohibited unless 9 * expressly authorized by QSS by written agreement. For more information 10 * (including whether this source code file has been published) please 11 * email licensing@qnx.com. $ 12 */ 13 14 /* 15 16 Copyright 2003 Free Software Foundation, Inc. 17 18 Contributed by QNX Software Systems Ltd. 19 20 This file is part of GDB. 21 22 This program is free software; you can redistribute it and/or modify 23 it under the terms of the GNU General Public License as published by 24 the Free Software Foundation; either version 2 of the License, or 25 (at your option) any later version. 26 27 This program is distributed in the hope that it will be useful, 28 but WITHOUT ANY WARRANTY; without even the implied warranty of 29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30 GNU General Public License for more details. 31 32 You should have received a copy of the GNU General Public License 33 along with this program; if not, write to the Free Software 34 Foundation, Inc., 59 Temple Place - Suite 330, 35 Boston, MA 02111-1307, USA. */ 36 37 #ifndef __DSMSGS_H__ 38 #define __DSMSGS_H__ 39 40 /* These are the protocol versioning numbers. 41 Update them with changes that introduce potential 42 compatibility issues. */ 43 #define PDEBUG_PROTOVER_MAJOR 0x00000000 44 #define PDEBUG_PROTOVER_MINOR 0x00000003 45 46 #include <stddef.h> 47 48 /* These are pdebug specific errors, sent sometimes with the errno after 49 an action failed. Simply provides additional info on the reason for the 50 error. Sent in the DSrMsg_err_t.hdr.subcmd byte. */ 51 52 #define PDEBUG_ENOERR 0 /* No error. */ 53 #define PDEBUG_ENOPTY 1 /* No Pseudo Terminals found. */ 54 #define PDEBUG_ETHREAD 2 /* Thread Create error. */ 55 #define PDEBUG_ECONINV 3 /* Invalid Console number. */ 56 #define PDEBUG_ESPAWN 4 /* Spawn error. */ 57 #define PDEBUG_EPROCFS 5 /* NTO Proc File System error. */ 58 #define PDEBUG_EPROCSTOP 6 /* NTO Process Stop error. */ 59 #define PDEBUG_EQPSINFO 7 /* QNX4 PSINFO error. */ 60 #define PDEBUG_EQMEMMODEL 8 /* QNX4 - Flat Memory Model only supported. */ 61 #define PDEBUG_EQPROXY 9 /* QNX4 Proxy error. */ 62 #define PDEBUG_EQDBG 10 /* QNX4 qnx_debug_* error. */ 63 64 /* There is room for pdebugerrnos up to sizeof(ut8). 65 66 We are moving away from the channel commands - only the RESET 67 and NAK are required. The DEBUG and TEXT channels are now part 68 of the DShdr and TShdr structs, 4th byte. GP June 1 1999. 69 They are still supported, but not required. 70 71 A packet containg a single byte is a set channel command. 72 IE: 7e xx chksum 7e 73 74 After a set channel all following packets are in the format 75 for the specified channel. Currently three channels are defined. 76 The raw channel has no structure. The other channels are all framed. 77 The contents of each channel is defined by structures below. 78 79 0 - Reset channel. Used when either end starts. 80 81 1 - Debug channel with the structure which follows below. 82 Uses DS (Debug Services) prefix. 83 84 2 - Text channel with the structure which follows below. 85 Uses TS (Text Services) prefix. 86 87 0xff - Negative acknowledgment of a packet transmission. */ 88 89 #define SET_CHANNEL_RESET 0 90 #define SET_CHANNEL_DEBUG 1 91 #define SET_CHANNEL_TEXT 2 92 #define SET_CHANNEL_NAK 0xff 93 94 /* Debug channel Messages: DS - Debug services. */ 95 96 /* Defines and structures for the debug channel. */ 97 98 #define DS_DATA_MAX_SIZE 1024 99 #define DS_DATA_RCV_SIZE(msg, total) \ 100 ((total) - (sizeof(*(msg)) - DS_DATA_MAX_SIZE)) 101 #define DS_MSG_OKSTATUS_FLAG 0x20000000 102 #define DS_MSG_OKDATA_FLAG 0x40000000 103 #define DS_MSG_NO_RESPONSE 0x80000000 104 105 #define QNXNTO_NSIG 57 /* From signals.h NSIG. */ 106 107 /* Common message header. It must be 32 or 64 bit aligned. 108 The top bit of cmd is 1 for BIG endian data format. */ 109 #define DSHDR_MSG_BIG_ENDIAN 0x80 110 struct DShdr { 111 ut8 cmd; 112 ut8 subcmd; 113 ut8 mid; 114 ut8 channel; 115 }; 116 117 /* Command types. */ 118 enum { 119 DStMsg_connect, /* 0 0x0 */ 120 DStMsg_disconnect, /* 1 0x1 */ 121 DStMsg_select, /* 2 0x2 */ 122 DStMsg_mapinfo, /* 3 0x3 */ 123 DStMsg_load, /* 4 0x4 */ 124 DStMsg_attach, /* 5 0x5 */ 125 DStMsg_detach, /* 6 0x6 */ 126 DStMsg_kill, /* 7 0x7 */ 127 DStMsg_stop, /* 8 0x8 */ 128 DStMsg_memrd, /* 9 0x9 */ 129 DStMsg_memwr, /* 10 0xA */ 130 DStMsg_regrd, /* 11 0xB */ 131 DStMsg_regwr, /* 12 0xC */ 132 DStMsg_run, /* 13 0xD */ 133 DStMsg_brk, /* 14 0xE */ 134 DStMsg_fileopen, /* 15 0xF */ 135 DStMsg_filerd, /* 16 0x10 */ 136 DStMsg_filewr, /* 17 0x11 */ 137 DStMsg_fileclose, /* 18 0x12 */ 138 DStMsg_pidlist, /* 19 0x13 */ 139 DStMsg_cwd, /* 20 0x14 */ 140 DStMsg_env, /* 21 0x15 */ 141 DStMsg_base_address, /* 22 0x16 */ 142 DStMsg_protover, /* 23 0x17 */ 143 DStMsg_handlesig, /* 24 0x18 */ 144 DStMsg_cpuinfo, /* 25 0x19 */ 145 DStMsg_tidnames, /* 26 0x1A */ 146 DStMsg_procfsinfo, /* 27 0x1B */ 147 /* Room for new codes here. */ 148 DSrMsg_err = 32, /* 32 0x20 */ 149 DSrMsg_ok, /* 33 0x21 */ 150 DSrMsg_okstatus, /* 34 0x22 */ 151 DSrMsg_okdata, /* 35 0x23 */ 152 /* Room for new codes here. */ 153 DShMsg_notify = 64 /* 64 0x40 */ 154 }; 155 156 /* Subcommand types. */ 157 enum { 158 DSMSG_LOAD_DEBUG, 159 DSMSG_LOAD_RUN, 160 DSMSG_LOAD_RUN_PERSIST, 161 DSMSG_LOAD_INHERIT_ENV = 0x80 162 }; 163 164 enum { 165 DSMSG_ENV_CLEARARGV, 166 DSMSG_ENV_ADDARG, 167 DSMSG_ENV_CLEARENV, 168 DSMSG_ENV_SETENV, 169 DSMSG_ENV_SETENV_MORE 170 }; 171 172 enum { DSMSG_STOP_PID, 173 DSMSG_STOP_PIDS }; 174 175 enum { DSMSG_SELECT_SET, 176 DSMSG_SELECT_QUERY }; 177 178 enum { DSMSG_KILL_PIDTID, 179 DSMSG_KILL_PID, 180 DSMSG_KILL_PIDS }; 181 182 enum { DSMSG_MEM_VIRTUAL, 183 DSMSG_MEM_PHYSICAL, 184 DSMSG_MEM_IO, 185 DSMSG_MEM_BASEREL }; 186 187 enum { 188 DSMSG_REG_GENERAL, 189 DSMSG_REG_FLOAT, 190 DSMSG_REG_SYSTEM, 191 DSMSG_REG_ALT, 192 DSMSG_REG_END 193 }; 194 195 enum { 196 DSMSG_RUN, 197 DSMSG_RUN_COUNT, 198 DSMSG_RUN_RANGE, 199 }; 200 201 enum { 202 DSMSG_PIDLIST_BEGIN, 203 DSMSG_PIDLIST_NEXT, 204 DSMSG_PIDLIST_SPECIFIC, 205 DSMSG_PIDLIST_SPECIFIC_TID, /* *_TID - send starting tid for the request, */ 206 }; /* and the response will have total to be sent. */ 207 208 enum { 209 DSMSG_CWD_QUERY, 210 DSMSG_CWD_SET, 211 }; 212 213 enum { 214 DSMSG_MAPINFO_BEGIN = 0x01, 215 DSMSG_MAPINFO_NEXT = 0x02, 216 DSMSG_MAPINFO_SPECIFIC = 0x04, 217 DSMSG_MAPINFO_ELF = 0x80, 218 }; 219 220 enum { 221 DSMSG_PROTOVER_MINOR = 222 0x000000FF, /* bit field (status & DSMSG_PROTOVER_MAJOR) */ 223 DSMSG_PROTOVER_MAJOR = 224 0x0000FF00, /* bit field (status & DSMSG_PROTOVER_MINOR) */ 225 }; 226 227 enum { 228 DSMSG_BRK_EXEC = 0x0001, /* Execution breakpoint. */ 229 DSMSG_BRK_RD = 0x0002, /* Read access (fail if not supported). */ 230 DSMSG_BRK_WR = 0x0004, /* Write access (fail if not supported). */ 231 DSMSG_BRK_RW = 0x0006, /* Read or write access (fail if not supported). */ 232 DSMSG_BRK_MODIFY = 0x0008, /* Memory modified. */ 233 DSMSG_BRK_RDM = 0x000a, /* Read access if suported otherwise modified. */ 234 DSMSG_BRK_WRM = 0x000c, /* Write access if suported otherwise modified. */ 235 DSMSG_BRK_RWM = 236 0x000e, /* Read or write access if suported otherwise modified. */ 237 DSMSG_BRK_HW = 0x0010, /* Only use hardware debugging (i.e. no singlestep). */ 238 }; 239 240 enum { 241 DSMSG_NOTIFY_PIDLOAD, /* 0 */ 242 DSMSG_NOTIFY_TIDLOAD, /* 1 */ 243 DSMSG_NOTIFY_DLLLOAD, /* 2 */ 244 DSMSG_NOTIFY_PIDUNLOAD, /* 3 */ 245 DSMSG_NOTIFY_TIDUNLOAD, /* 4 */ 246 DSMSG_NOTIFY_DLLUNLOAD, /* 5 */ 247 DSMSG_NOTIFY_BRK, /* 6 */ 248 DSMSG_NOTIFY_STEP, /* 7 */ 249 DSMSG_NOTIFY_SIGEV, /* 8 */ 250 DSMSG_NOTIFY_STOPPED /* 9 */ 251 }; 252 253 /* Messages sent to the target. DStMsg_* (t - for target messages). */ 254 255 /* Connect to the agent running on the target. */ 256 typedef struct { 257 struct DShdr hdr; 258 ut8 major; 259 ut8 minor; 260 ut8 spare[2]; 261 } DStMsg_connect_t; 262 263 /* Disconnect from the agent running on the target. */ 264 typedef struct { struct DShdr hdr; } DStMsg_disconnect_t; 265 266 /* Select a pid, tid for subsequent messages or query their validity. */ 267 typedef struct { 268 struct DShdr hdr; 269 st32 pid; 270 st32 tid; 271 } DStMsg_select_t; 272 273 /* Return information on what is at the specified virtual address. 274 If nothing is there we return info on the next thing in the address. */ 275 typedef struct { 276 struct DShdr hdr; 277 st32 pid; 278 st32 addr; 279 } DStMsg_mapinfo_t; 280 281 /* Load a new process into memory for a filesystem. */ 282 typedef struct { 283 struct DShdr hdr; 284 st32 argc; 285 st32 envc; 286 char cmdline[DS_DATA_MAX_SIZE]; 287 } DStMsg_load_t; 288 289 /* Attach to an already running process. */ 290 typedef struct { 291 struct DShdr hdr; 292 st32 pid; 293 } DStMsg_attach_t; 294 295 typedef DStMsg_attach_t DStMsg_procfsinfo_t; 296 297 /* Detach from a running process which was attached to or loaded. */ 298 typedef struct { 299 struct DShdr hdr; 300 st32 pid; 301 } DStMsg_detach_t; 302 303 /* Set a signal on a process. */ 304 typedef struct { 305 struct DShdr hdr; 306 st32 signo; 307 } DStMsg_kill_t; 308 309 /* Stop one or more processes/threads. */ 310 typedef struct { struct DShdr hdr; } DStMsg_stop_t; 311 312 /* Memory read request. */ 313 typedef struct { 314 struct DShdr hdr; 315 ut32 spare0; 316 ut64 addr; 317 ut16 size; 318 } DStMsg_memrd_t; 319 320 /* Memory write request. */ 321 typedef struct { 322 struct DShdr hdr; 323 ut32 spare0; 324 ut64 addr; 325 ut8 data[DS_DATA_MAX_SIZE]; 326 } DStMsg_memwr_t; 327 328 /* Register read request. */ 329 typedef struct { 330 struct DShdr hdr; 331 ut16 offset; 332 ut16 size; 333 } DStMsg_regrd_t; 334 335 /* Register write request. */ 336 typedef struct { 337 struct DShdr hdr; 338 ut16 offset; 339 ut8 data[DS_DATA_MAX_SIZE]; 340 } DStMsg_regwr_t; 341 342 /* Run. */ 343 typedef struct { 344 struct DShdr hdr; 345 union { 346 ut32 count; 347 ut32 addr[2]; 348 } step; 349 } DStMsg_run_t; 350 351 /* Break. */ 352 typedef struct { 353 struct DShdr hdr; 354 ut32 addr; 355 ut32 size; 356 } DStMsg_brk_t; 357 358 /* Open a file on the target. */ 359 typedef struct { 360 struct DShdr hdr; 361 st32 mode; 362 st32 perms; 363 char pathname[DS_DATA_MAX_SIZE]; 364 } DStMsg_fileopen_t; 365 366 /* Read a file on the target. */ 367 typedef struct { 368 struct DShdr hdr; 369 ut16 size; 370 } DStMsg_filerd_t; 371 372 /* Write a file on the target. */ 373 typedef struct { 374 struct DShdr hdr; 375 ut8 data[DS_DATA_MAX_SIZE]; 376 } DStMsg_filewr_t; 377 378 /* Close a file on the target. */ 379 typedef struct { 380 struct DShdr hdr; 381 st32 mtime; 382 } DStMsg_fileclose_t; 383 384 /* Get pids and process names in the system. */ 385 typedef struct { 386 struct DShdr hdr; 387 st32 pid; /* Only valid for type subtype SPECIFIC. */ 388 st32 tid; /* Tid to start reading from. */ 389 } DStMsg_pidlist_t; 390 391 /* Set current working directory of process. */ 392 typedef struct { 393 struct DShdr hdr; 394 ut8 path[DS_DATA_MAX_SIZE]; 395 } DStMsg_cwd_t; 396 397 /* Clear, set, get environment for new process. */ 398 typedef struct { 399 struct DShdr hdr; 400 char data[DS_DATA_MAX_SIZE]; 401 } DStMsg_env_t; 402 403 /* Get the base address of a process. */ 404 typedef struct { struct DShdr hdr; } DStMsg_baseaddr_t; 405 406 /* Send pdebug protocol version info, get the same in response_ok_status. */ 407 typedef struct { 408 struct DShdr hdr; 409 ut8 major; 410 ut8 minor; 411 } DStMsg_protover_t; 412 413 /* Handle signal message. */ 414 typedef struct { 415 struct DShdr hdr; 416 ut8 signals[QNXNTO_NSIG]; 417 ut32 sig_to_pass; 418 } DStMsg_handlesig_t; 419 420 /* Get some cpu info. */ 421 typedef struct { 422 struct DShdr hdr; 423 ut32 spare; 424 } DStMsg_cpuinfo_t; 425 426 /* Get the names of the threads */ 427 typedef struct { 428 struct DShdr hdr; 429 ut32 spare; 430 } DStMsg_tidnames_t; 431 432 /* Messages sent to the host. DStMsg_* (h - for host messages). */ 433 434 /* Notify host that something happened it needs to know about. */ 435 #define NOTIFY_HDR_SIZE offsetof (DShMsg_notify_t, un) 436 #define NOTIFY_MEMBER_SIZE(member) sizeof(member) 437 438 typedef struct { 439 struct DShdr hdr; 440 st32 pid; 441 st32 tid; 442 union { 443 struct { 444 ut32 codeoff; 445 ut32 dataoff; 446 ut16 ostype; 447 ut16 cputype; 448 ut32 cpuid; /* CPU dependant value. */ 449 char name[DS_DATA_MAX_SIZE]; 450 } pidload; 451 struct { 452 st32 status; 453 } pidunload; 454 struct { 455 st32 status; 456 ut8 faulted; 457 ut8 reserved[3]; 458 } pidunload_v3; 459 struct { 460 ut32 ip; 461 ut32 dp; 462 ut32 flags; /* Defined in <sys/debug.h>. */ 463 } brk; 464 struct { 465 ut32 ip; 466 ut32 lastip; 467 } step; 468 struct { 469 st32 signo; 470 st32 code; 471 st32 value; 472 } sigev; 473 } un; 474 } DShMsg_notify_t; 475 476 /* Responses to a message. DSrMsg_* (r - for response messages). */ 477 478 /* Error response packet. */ 479 typedef struct { 480 struct DShdr hdr; 481 st32 err; 482 } DSrMsg_err_t; 483 484 /* Simple OK response. */ 485 typedef struct { struct DShdr hdr; } DSrMsg_ok_t; 486 487 /* Simple OK response with a result. Used where limited data needs 488 to be returned. For example, if the number of bytes which were 489 successfully written was less than requested on any write cmd the 490 status will be the number actually written. 491 The 'subcmd' will always be zero. */ 492 typedef struct { 493 struct DShdr hdr; 494 st32 status; 495 } DSrMsg_okstatus_t; 496 497 /* The following structures overlay data[..] on a DSrMsg_okdata_t. */ 498 struct dslinkmap { 499 ut32 addr; 500 ut32 size; 501 ut32 flags; 502 ut32 debug_vaddr; 503 ut64 offset; 504 }; 505 506 struct dsmapinfo { 507 struct dsmapinfo *next; 508 ut32 spare0; 509 ut64 ino; 510 ut32 dev; 511 ut32 spare1; 512 struct dslinkmap text; 513 struct dslinkmap data; 514 char name[256]; 515 }; 516 517 struct dspidlist { 518 st32 pid; 519 st32 num_tids; /* Num of threads this pid has. */ 520 st32 spare[6]; 521 struct tidinfo { 522 st16 tid; 523 ut8 state; 524 ut8 flags; 525 } tids[1]; /* Variable length terminated by tid==0. */ 526 char name[1]; /* Variable length terminated by \0. */ 527 }; 528 529 struct dscpuinfo { 530 ut32 cpuflags; 531 ut32 spare1; 532 ut32 spare2; 533 ut32 spare3; 534 }; 535 536 struct dstidnames { 537 ut32 numtids; 538 ut32 numleft; 539 ut32 spare1; 540 ut32 spare2; 541 char data[1]; /* A bunch of string data tidNULLnameNULL... */ 542 }; 543 544 /* Long OK response with 0..DS_DATA_MAX_SIZE data. 545 The 'subcmd' will always be zero. */ 546 typedef struct { 547 struct DShdr hdr; 548 ut8 data[DS_DATA_MAX_SIZE]; 549 } DSrMsg_okdata_t; 550 551 /* A union of all possible messages and responses. */ 552 typedef union { 553 struct DShdr hdr; 554 DStMsg_connect_t connect; 555 DStMsg_disconnect_t disconnect; 556 DStMsg_select_t select; 557 DStMsg_load_t load; 558 DStMsg_attach_t attach; 559 DStMsg_procfsinfo_t procfsinfo; 560 DStMsg_detach_t detach; 561 DStMsg_kill_t kill; 562 DStMsg_stop_t stop; 563 DStMsg_memrd_t memrd; 564 DStMsg_memwr_t memwr; 565 DStMsg_regrd_t regrd; 566 DStMsg_regwr_t regwr; 567 DStMsg_run_t run; 568 DStMsg_brk_t brk; 569 DStMsg_fileopen_t fileopen; 570 DStMsg_filerd_t filerd; 571 DStMsg_filewr_t filewr; 572 DStMsg_fileclose_t fileclose; 573 DStMsg_pidlist_t pidlist; 574 DStMsg_mapinfo_t mapinfo; 575 DStMsg_cwd_t cwd; 576 DStMsg_env_t env; 577 DStMsg_baseaddr_t baseaddr; 578 DStMsg_protover_t protover; 579 DStMsg_handlesig_t handlesig; 580 DStMsg_cpuinfo_t cpuinfo; 581 DStMsg_tidnames_t tidnames; 582 DShMsg_notify_t notify; 583 DSrMsg_err_t err; 584 DSrMsg_ok_t ok; 585 DSrMsg_okstatus_t okstatus; 586 DSrMsg_okdata_t okdata; 587 } DSMsg_union_t; 588 589 /* Text channel Messages: TS - Text services. */ 590 #define TS_TEXT_MAX_SIZE 100 591 592 /* Command types. */ 593 enum { 594 TSMsg_text, /* 0 */ 595 TSMsg_done, /* 1 */ 596 TSMsg_start, /* 2 */ 597 TSMsg_stop, /* 3 */ 598 TSMsg_ack, /* 4 */ 599 }; 600 601 struct TShdr { 602 ut8 cmd; 603 ut8 console; 604 ut8 spare1; 605 ut8 channel; 606 }; 607 608 /* Deliver text. This message can be sent by either side. 609 The debugger displays it in a window. The agent gives it to a pty 610 which a program may be listening on. */ 611 typedef struct { 612 struct TShdr hdr; 613 char text[TS_TEXT_MAX_SIZE]; 614 } TSMsg_text_t; 615 616 /* There is no longer a program connected to this console. */ 617 typedef struct { struct TShdr hdr; } TSMsg_done_t; 618 619 /* TextStart or TextStop flow control. */ 620 typedef struct { struct TShdr hdr; } TSMsg_flowctl_t; 621 622 /* Ack a flowctl message. */ 623 typedef struct { struct TShdr hdr; } TSMsg_ack_t; 624 625 #endif 626