GdbPacket.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * @author: 2019 - Mikee47 <mike@sillyhouse.net>
8  *
9  * Manages GDB packet encoding. See here for details:
10  *
11  * https://sourceware.org/gdb/current/onlinedocs/gdb/Remote-Protocol.html
12  *
13  ****/
14 
15 #pragma once
16 
17 #include "gdbuart.h"
18 
19 class GdbPacket
20 {
21 public:
22  // Automatically start sending a packet
23  __forceinline GdbPacket()
24  {
25  start();
26  }
27 
28  // Finish sending a packet
29  __forceinline ~GdbPacket()
30  {
31  end();
32  }
33 
34  // Send a char as part of a packet
35  void writeChar(char c);
36 
38  void writeCharEscaped(char c);
39 
41  void writeEscaped(const void* data, unsigned length);
42 
44  void writeHexByte(uint8_t value);
45 
47  void writeHexWord16(uint16_t value);
48 
50  void writeHexWord32(uint32_t value);
51 
57  void writeHexBlock(const void* src, size_t size);
58 
60  void writeX32();
61 
63  void write(const void* data, unsigned length);
64 
66  void writeStr(const char* str);
67 
69  void writeStrRef(const char* str);
70 
71  size_t getLength()
72  {
73  return packetLength + 3; // Include # and checksum digits
74  }
75 
81  static uint32_t readHexValue(const char*& data);
82 
89  static void encodeHexBlock(char* dst, const void* src, size_t size);
90 
97  static size_t decodeHexBlock(void* dst, const char*& src);
98 
99 private:
100  // Send the start of a packet; reset checksum calculation.
101  void start();
102 
103  // Finish sending a packet.
104  void end();
105 
106 private:
107  uint8_t checksum = 0;
108  unsigned packetLength = 0;
109 };
Definition: GdbPacket.h:20
void writeHexWord16(uint16_t value)
Output 16-bit value.
void write(const void *data, unsigned length)
Output block of data exactly as given without escaping.
size_t getLength()
Definition: GdbPacket.h:71
void writeStrRef(const char *str)
Output a string reference in addr/len format.
void writeEscaped(const void *data, unsigned length)
Send a block of data, escaping as required.
void writeHexBlock(const void *src, size_t size)
Output a block of data, hex-encoded.
void writeX32()
Output 'xxxxxxxx' to indicate undefined register value.
void writeCharEscaped(char c)
Send a character, escaping if required.
void writeHexWord32(uint32_t value)
Output 32-bit value.
static uint32_t readHexValue(const char *&data)
Decode a variable-length hex value, MSB first.
void writeChar(char c)
~GdbPacket()
Definition: GdbPacket.h:29
void writeHexByte(uint8_t value)
Output 8-bit value.
static size_t decodeHexBlock(void *dst, const char *&src)
Decode hex-encoded data block.
static void encodeHexBlock(char *dst, const void *src, size_t size)
Encode a value as hex characters, LSB first.
void writeStr(const char *str)
Output a null-terminated string exactly as given without escaping.
GdbPacket()
Definition: GdbPacket.h:23
#define str(s)
Definition: testrunner.h:124