Skip to content

Commit a3112ab

Browse files
akosthekissyichoi
authored andcommitted
Split string-sending debugger API into output- and log-sending functions (#2461)
This helps to avoid the use of non-public headers and protocol-internal constants in external code (e.g., in jerry-port and jerry-ext). The patch also cleans up the necessary includes in jerry-core public headers, and the include order in jerry-port/default public headers. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss [email protected]
1 parent b9aa0da commit a3112ab

File tree

8 files changed

+75
-18
lines changed

8 files changed

+75
-18
lines changed

docs/07.DEBUGGER.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,20 +359,51 @@ Sends the program's output to the debugger client.
359359
**Prototype**
360360

361361
```c
362-
void
363-
jerry_debugger_send_output (jerry_char_t buffer[], jerry_size_t string_size, uint8_t type)
362+
void
363+
jerry_debugger_send_output (jerry_char_t buffer[], jerry_size_t string_size)
364364
```
365365
366366
**Example**
367367
368368
```c
369+
{
369370
jerry_init (JERRY_INIT_EMPTY);
370371
jerry_debugger_init (5001);
371372
372373
jerry_char_t my_output = "Hey, this should be sent too!";
373374
jerry_size_t my_output_size = sizeof (my_output);
374375
375-
jerry_debugger_send_output (my_output, my_output_size, JERRY_DEBUGGER_OUTPUT_OK);
376+
jerry_debugger_send_output (my_output, my_output_size);
377+
378+
jerry_cleanup ();
379+
}
380+
```
381+
382+
### jerry_debugger_send_log
383+
384+
**Summary**
385+
386+
Sends the program's log to the debugger client.
387+
388+
**Prototype**
389+
390+
```c
391+
void
392+
jerry_debugger_send_log (jerry_log_level_t level, jerry_char_t buffer[], jerry_size_t string_size)
393+
```
394+
395+
**Example**
396+
397+
```c
398+
{
399+
jerry_init (JERRY_INIT_EMPTY);
400+
jerry_debugger_init (5001);
401+
402+
jerry_char_t my_log = "Custom diagnostics";
403+
jerry_size_t my_log_size = sizeof (my_log);
404+
405+
jerry_debugger_send_log (JERRY_LOG_LEVEL_DEBUG, my_log, my_log_size);
376406
377407
jerry_cleanup ();
408+
}
378409
```

jerry-core/api/jerry-debugger.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,41 @@ jerry_debugger_wait_for_client_source (jerry_debugger_wait_for_source_callback_t
190190
*/
191191
void
192192
jerry_debugger_send_output (jerry_char_t buffer[], /**< buffer */
193-
jerry_size_t str_size, /**< string size */
194-
uint8_t type) /**< type of output */
193+
jerry_size_t str_size) /**< string size */
195194
{
196195
#ifdef JERRY_DEBUGGER
197196
if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
198197
{
199198
jerry_debugger_send_string (JERRY_DEBUGGER_OUTPUT_RESULT,
200-
type,
199+
JERRY_DEBUGGER_OUTPUT_OK,
201200
(const uint8_t *) buffer,
202201
sizeof (uint8_t) * str_size);
203202
}
204203
#else /* !JERRY_DEBUGGER */
205204
JERRY_UNUSED (buffer);
206205
JERRY_UNUSED (str_size);
207-
JERRY_UNUSED (type);
208206
#endif /* JERRY_DEBUGGER */
209207
} /* jerry_debugger_send_output */
208+
209+
/**
210+
* Send the log of the program to the debugger client.
211+
*/
212+
void
213+
jerry_debugger_send_log (jerry_log_level_t level, /**< level of the diagnostics message */
214+
jerry_char_t buffer[], /**< buffer */
215+
jerry_size_t str_size) /**< string size */
216+
{
217+
#ifdef JERRY_DEBUGGER
218+
if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
219+
{
220+
jerry_debugger_send_string (JERRY_DEBUGGER_OUTPUT_RESULT,
221+
(uint8_t) (level + 2),
222+
(const uint8_t *) buffer,
223+
sizeof (uint8_t) * str_size);
224+
}
225+
#else /* !JERRY_DEBUGGER */
226+
JERRY_UNUSED (level);
227+
JERRY_UNUSED (buffer);
228+
JERRY_UNUSED (str_size);
229+
#endif /* JERRY_DEBUGGER */
230+
} /* jerry_debugger_send_log */

jerry-core/debugger/debugger.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ typedef enum
212212

213213
/**
214214
* Subtypes of output_result.
215+
*
216+
* Note:
217+
* This enum has to be kept in sync with jerry_log_level_t with an offset
218+
* of +2.
215219
*/
216220
typedef enum
217221
{

jerry-core/include/jerryscript-debugger-transport.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
#ifndef JERRYSCRIPT_DEBUGGER_TRANSPORT_H
1717
#define JERRYSCRIPT_DEBUGGER_TRANSPORT_H
1818

19-
#include "jerryscript-core.h"
19+
#include <stdbool.h>
20+
#include <stddef.h>
21+
#include <stdint.h>
2022

2123
#ifdef __cplusplus
2224
extern "C"

jerry-core/include/jerryscript-debugger.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define JERRYSCRIPT_DEBUGGER_H
1818

1919
#include "jerryscript-core.h"
20+
#include "jerryscript-port.h"
2021

2122
#ifdef __cplusplus
2223
extern "C"
@@ -60,7 +61,8 @@ void jerry_debugger_stop_at_breakpoint (bool enable_stop_at_breakpoint);
6061
jerry_debugger_wait_for_source_status_t
6162
jerry_debugger_wait_for_client_source (jerry_debugger_wait_for_source_callback_t callback_p,
6263
void *user_p, jerry_value_t *return_value);
63-
void jerry_debugger_send_output (jerry_char_t buffer[], jerry_size_t str_size, uint8_t type);
64+
void jerry_debugger_send_output (jerry_char_t buffer[], jerry_size_t str_size);
65+
void jerry_debugger_send_log (jerry_log_level_t level, jerry_char_t buffer[], jerry_size_t str_size);
6466

6567
/**
6668
* @}

jerry-ext/handler/handler-print.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
#include "jerryscript-ext/handler.h"
17-
#include "debugger.h"
17+
#include "jerryscript-debugger.h"
1818

1919
/**
2020
* Provide a 'print' implementation for scripts.
@@ -72,7 +72,7 @@ jerryx_handler_print (const jerry_value_t func_obj_val, /**< function object */
7272
256)) != 0)
7373
{
7474
#ifdef JERRY_DEBUGGER
75-
jerry_debugger_send_output (substr_buf, substr_size, JERRY_DEBUGGER_OUTPUT_OK);
75+
jerry_debugger_send_output (substr_buf, substr_size);
7676
#endif /* JERRY_DEBUGGER */
7777
for (jerry_size_t chr_index = 0; chr_index < substr_size; chr_index++)
7878
{

jerry-port/default/default-io.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include "jerryscript-port.h"
1919
#include "jerryscript-port-default.h"
20-
#include "debugger.h"
20+
#include "jerryscript-debugger.h"
2121

2222
#ifndef DISABLE_EXTRA_API
2323

@@ -91,10 +91,7 @@ jerry_port_log (jerry_log_level_t level, /**< message log level */
9191
vsnprintf (buffer, (size_t) length + 1, format, args);
9292

9393
fprintf (stderr, "%s", buffer);
94-
if (jerry_debugger_transport_is_connected ())
95-
{
96-
jerry_debugger_send_output ((jerry_char_t *) buffer, (jerry_size_t) length, (uint8_t) (level + 2));
97-
}
94+
jerry_debugger_send_log (level, (jerry_char_t *) buffer, (jerry_size_t) length);
9895
#else /* If jerry-debugger isn't defined, libc is turned on */
9996
vfprintf (stderr, format, args);
10097
#endif /* JERRY_DEBUGGER */

jerry-port/default/include/jerryscript-port-default.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
#ifndef JERRYSCRIPT_PORT_DEFAULT_H
1717
#define JERRYSCRIPT_PORT_DEFAULT_H
1818

19+
#include <stdbool.h>
20+
1921
#include "jerryscript.h"
2022
#include "jerryscript-port.h"
2123

22-
#include <stdbool.h>
23-
2424
#ifdef __cplusplus
2525
extern "C"
2626
{

0 commit comments

Comments
 (0)