Add timeout to jerry_debugger_receive (#1885)
Fixed when debug server uses a CPU core on 100%. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
@@ -181,6 +181,16 @@ if(FEATURE_DEBUGGER)
|
||||
message(FATAL_ERROR "This configuration is not supported. Please build against your system libc to enable the JerryScript debugger.")
|
||||
endif()
|
||||
|
||||
# Sleep function availability check
|
||||
INCLUDE (CheckIncludeFiles)
|
||||
CHECK_INCLUDE_FILES (time.h HAVE_TIME_H)
|
||||
CHECK_INCLUDE_FILES (unistd.h HAVE_UNISTD_H)
|
||||
if(HAVE_TIME_H)
|
||||
set(DEFINES_JERRY ${DEFINES_JERRY} HAVE_TIME_H)
|
||||
elseif(HAVE_UNISTD_H)
|
||||
set(DEFINES_JERRY ${DEFINES_JERRY} HAVE_UNISTD_H)
|
||||
endif()
|
||||
|
||||
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_DEBUGGER)
|
||||
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_DEBUGGER_PORT=${FEATURE_DEBUGGER_PORT})
|
||||
endif()
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 500 /* Required macro for sleep functions */
|
||||
|
||||
#include "byte-code.h"
|
||||
#include "debugger.h"
|
||||
#include "ecma-builtin-helpers.h"
|
||||
@@ -25,6 +27,12 @@
|
||||
|
||||
#ifdef JERRY_DEBUGGER
|
||||
|
||||
#ifdef HAVE_TIME_H
|
||||
#include <time.h>
|
||||
#elif defined (HAVE_UNISTD_H)
|
||||
#include <unistd.h>
|
||||
#endif /* HAVE_TIME_H */
|
||||
|
||||
/**
|
||||
* Type cast the debugger send buffer into a specific type.
|
||||
*/
|
||||
@@ -37,6 +45,11 @@
|
||||
#define JERRY_DEBUGGER_RECEIVE_BUFFER_AS(type, name_p) \
|
||||
type *name_p = ((type *) recv_buffer_p)
|
||||
|
||||
/**
|
||||
* Sleep time in milliseconds between each jerry_debugger_receive call
|
||||
*/
|
||||
#define JERRY_DEBUGGER_TIMEOUT 100
|
||||
|
||||
/**
|
||||
* Free all unreferenced byte code structures which
|
||||
* were not acknowledged by the debugger client.
|
||||
@@ -201,6 +214,24 @@ jerry_debugger_send_eval (const lit_utf8_byte_t *eval_string_p, /**< evaluated s
|
||||
return success;
|
||||
} /* jerry_debugger_send_eval */
|
||||
|
||||
/**
|
||||
* Suspend execution for a given time.
|
||||
* Note: If the platform does not have nanosleep or usleep, this function does not sleep at all.
|
||||
*/
|
||||
static void
|
||||
jerry_debugger_sleep (unsigned milliseconds) /**< suspending time */
|
||||
{
|
||||
#ifdef HAVE_TIME_H
|
||||
nanosleep (&(const struct timespec)
|
||||
{
|
||||
milliseconds / 1000, (milliseconds % 1000) * 1000000L /* Seconds, nanoseconds */
|
||||
}
|
||||
, NULL);
|
||||
#elif defined (HAVE_UNISTD_H)
|
||||
usleep ((useconds_t) milliseconds * 1000);
|
||||
#endif /* HAVE_TIME_H */
|
||||
} /* jerry_debugger_sleep */
|
||||
|
||||
/**
|
||||
* Check received packet size.
|
||||
*/
|
||||
@@ -514,6 +545,7 @@ jerry_debugger_breakpoint_hit (uint8_t message_type) /**< message type */
|
||||
|
||||
while (!jerry_debugger_receive ())
|
||||
{
|
||||
jerry_debugger_sleep (JERRY_DEBUGGER_TIMEOUT);
|
||||
}
|
||||
|
||||
JERRY_CONTEXT (debugger_flags) = (uint8_t) (JERRY_CONTEXT (debugger_flags) & ~JERRY_DEBUGGER_BREAKPOINT_MODE);
|
||||
|
||||
Reference in New Issue
Block a user