<commit_before>#include "dbg_impl.h"
#include "dbg_protocol.h"  
#include "dbg_network.h"	 
#include "dbg_format.h"
#include <thread>

namespace vscode
{
	static debugger_impl* global_debugger;
	void debugger_impl::debughook(lua_State *L, lua_Debug *ar)
	{
		if (!ar || !global_debugger)
			return;
		global_debugger->hook(L, ar);
	}

	void debugger_impl::open()
	{
		redirect_.open();
		global_debugger = this;
		stacklevel_ = 0;
		lua_sethook(GL, debugger_impl::debughook, LUA_MASKCALL | LUA_MASKLINE | LUA_MASKRET, 0);
	}

	void debugger_impl::close()
	{
		redirect_.close();
		global_debugger = 0;
		lua_sethook(GL, 0, 0, 0);
		breakpoints_.clear();
		stack_.clear();
		workingdir_.clear();
		seq = 1;
		stacklevel_ = 0;
	}

	void debugger_impl::update_redirect()
	{
		size_t n = 0;
		n = redirect_.peek_stdout();
		if (n > 1)
		{
			hybridarray<char, 1024> buf(n);
			redirect_.read_stdout(buf.data(), buf.size());
			event_output("stdout", buf);
		}
		n = redirect_.peek_stdout();
		if (n > 0)
		{
			hybridarray<char, 1024> buf(n);
			redirect_.read_stdout(buf.data(), buf.size());
			event_output("stderr", buf);
		}
	}

	bool debugger_impl::update_main(rprotocol& req, bool& quit)
	{
		auto& command = req["command"];
		auto it = main_dispatch_.find(std::string(command.GetString(), command.GetStringLength()));
		if (it != main_dispatch_.end())
		{
			quit = it->second(req);
			return true;
		}
		return false;
	}

	bool debugger_impl::update_hook(rprotocol& req, lua_State *L, lua_Debug *ar, bool& quit)
	{
		auto& command = req["command"];
		auto it = hook_dispatch_.find(std::string(command.GetString(), command.GetStringLength()));
		if (it != hook_dispatch_.end())
		{
			quit = it->second(req, L, ar);
			return true;
		}
		return false;
	}

	void debugger_impl::hook(lua_State *L, lua_Debug *ar)
	{
		if (ar->event == LUA_HOOKCALL)
		{
			stacklevel_++;
			return;
		}
		if (ar->event == LUA_HOOKRET)
		{
			stacklevel_--;
			return;
		}
		if (ar->event != LUA_HOOKLINE)
			return;
		if (is_state(state::terminated)) {
			return;
		}

		if (is_state(state::running)) {
			if (!check_breakpoint(L, ar)) {
				return;
			}
		}

		if (is_state(state::stepping)) {
			if (is_step(step::out) || is_step(step::over)) {
				if (!check_breakpoint(L, ar)) {
					if (!check_step(L, ar)) {
						return;
					}
				}
			}
			event_stopped("step");
			step_in();
		}

		bool quit = false;
		while (!quit)
		{
			network_->update(0);<commit_msg>断点触发时的停止事件<commit_after>#include "dbg_impl.h"
#include "dbg_protocol.h"  
#include "dbg_network.h"	 
#include "dbg_format.h"
#include <thread>

namespace vscode
{
	static debugger_impl* global_debugger;
	void debugger_impl::debughook(lua_State *L, lua_Debug *ar)
	{
		if (!ar || !global_debugger)
			return;
		global_debugger->hook(L, ar);
	}

	void debugger_impl::open()
	{
		redirect_.open();
		global_debugger = this;
		stacklevel_ = 0;
		lua_sethook(GL, debugger_impl::debughook, LUA_MASKCALL | LUA_MASKLINE | LUA_MASKRET, 0);
	}

	void debugger_impl::close()
	{
		redirect_.close();
		global_debugger = 0;
		lua_sethook(GL, 0, 0, 0);
		breakpoints_.clear();
		stack_.clear();
		workingdir_.clear();
		seq = 1;
		stacklevel_ = 0;
	}

	void debugger_impl::update_redirect()
	{
		size_t n = 0;
		n = redirect_.peek_stdout();
		if (n > 1)
		{
			hybridarray<char, 1024> buf(n);
			redirect_.read_stdout(buf.data(), buf.size());
			event_output("stdout", buf);
		}
		n = redirect_.peek_stdout();
		if (n > 0)
		{
			hybridarray<char, 1024> buf(n);
			redirect_.read_stdout(buf.data(), buf.size());
			event_output("stderr", buf);
		}
	}

	bool debugger_impl::update_main(rprotocol& req, bool& quit)
	{
		auto& command = req["command"];
		auto it = main_dispatch_.find(std::string(command.GetString(), command.GetStringLength()));
		if (it != main_dispatch_.end())
		{
			quit = it->second(req);
			return true;
		}
		return false;
	}

	bool debugger_impl::update_hook(rprotocol& req, lua_State *L, lua_Debug *ar, bool& quit)
	{
		auto& command = req["command"];
		auto it = hook_dispatch_.find(std::string(command.GetString(), command.GetStringLength()));
		if (it != hook_dispatch_.end())
		{
			quit = it->second(req, L, ar);
			return true;
		}
		return false;
	}

	void debugger_impl::hook(lua_State *L, lua_Debug *ar)
	{
		if (ar->event == LUA_HOOKCALL)
		{
			stacklevel_++;
			return;
		}
		if (ar->event == LUA_HOOKRET)
		{
			stacklevel_--;
			return;
		}
		if (ar->event != LUA_HOOKLINE)
			return;
		if (is_state(state::terminated)) {
			return;
		}

		bool bp = false;
		if (is_state(state::running)) {
			if (!check_breakpoint(L, ar)) {
				return;
			}
			bp = true;
		}

		if (is_state(state::stepping)) {
			if (is_step(step::out) || is_step(step::over)) {
				if (!check_breakpoint(L, ar)) {
					if (!check_step(L, ar)) {
						return;
					}
				}
				else {
					bp = true;
				}
			}
			if (bp)
				event_stopped("breakpoint");
			else
				event_stopped("step");
			step_in();
		}

		bool quit = false;
		while (!quit)
		{
			network_->update(0);
{'fraction_non_alphanumeric': 0.1648066958947788, 'fraction_numerical': 0.007971303308090873, 'mean_word_length': 3.642923219241443, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '868328', 'n_tokens_mistral': 2285, 'n_tokens_neox': 1954, 'n_words': 371}