scite_require 'debugger.lua' local find = string.find local sub = string.sub local gsub = string.gsub local GTK = scite_GetProp('PLAT_GTK') local p_pattern = '^= ' local function print_process(s, dbg) s = s:sub(3) display(dbg.last_arg..' = '..s) end -- special actions for commands which require postprocessing local postprocess_command = { eval = {pattern = p_pattern, action = print_process, single_pattern = true}, } Remdebug = class(Dbg) -- RemDebug is now only used for _remote connections_ if Clidebug is also registered! function Remdebug.discriminator(target) return find(target, ':') == 1 end function Remdebug:init(root) local dir = scite_GetProp('debug.path.local') if dir then dir = dir:gsub('\\', '/') if not find(dir, "/$")then dir = dir .. "/" end local _, _, res, path = find(dir, '^([^%.\\/]+)(:.*)$') self.local_dir = res:upper()..path print('local_dir:'..self.local_dir) else self.local_dir = nil end dir = scite_GetProp('debug.path.remote') if dir then dir = dir:gsub('\\', '/') if not find(dir, "/$")then dir = dir .. "/" end _, _, res, path = find(dir, '^([^%.\\/]+)(:.*)$') self.remote_dir = res:upper()..path print('remote_dir:'..self.remote_dir) else self.remote_dir = nil end self.prompt = 'DBG>' self.no_target_ext = false self.cmd_file = root..'/dbg.cmd' self.detect_start = '^Run the program you wish to debug' -- find out where the Lua executable is; you can use the debug.lua property if it isn't the same -- as your lua executable specified in lua.properties. self.lua = scite_GetProp("debug.lua") if not self.lua then self.lua = scite_GetProp('command.go.*.lua'):match('^(%w+)') end -- this is added to the package.path of the Lua program self.remdebug_path = scite_GetProp('remdebug.path', extman_Path()..'/remDebug') self.no_quit_confirm = true local drive = ''; if not GTK then drive = '[a-zA-Z]:' end self.break_line = '^Paused at file ('..drive..'/[^%s]+)%sline%s(%d+)' self.silent_command = {} self.postprocess_command = postprocess_command end local function backslash(path) return path:gsub('\\', '/') end function Remdebug:handle_debug_start() if not self.target:find('^:remote')then local cmd = self.lua..' -e "package.path=\''..backslash(self.remdebug_path) cmd = cmd..'/?.lua;\'..package.path" -l remdebug '..self.target..' '..self:parameter_string() print(cmd) print 'spawning...' ts = spawner.new(cmd) ts:set_output('trace') ts:run() end end -- '%s -e "package.path=%s" -l remdebug %s' local GTK = scite_GetProp('PLAT_GTK') function Remdebug:command_line(target) self.target = target local luapath = scite_GetProp('lua.path') local port = scite_GetProp('debug.Port') local rpath = self.remdebug_path return luapath ..'\\' .. self.lua..' -e "_DPORT=' .. port .. ' " -e "_DPROMPT=\'' .. self.prompt .. '\\n\'" '..rpath..'/controller.lua '..self.cmd_file end local breakpoint_exit = false function Remdebug:dump_breakpoints(out) breakpoint_exit = false for b in Breakpoints()do local file = b.file:gsub('\\', '/') if self.local_dir and self.local_dir ~= "" and self.remote_dir and self.remote_dir ~= "" then local file_tmp = file file = gsub(file_tmp, self.local_dir, self.remote_dir) scite_debug('set_breakpoint(local to remote):'..file_tmp..'->'..file..' ('..b.line..')') end out:write('setb '..file..' '..b.line..'\n') breakpoint_exit = true end end function Remdebug:run_program(out, parms) if breakpoint_exit then out:write('run\n') else out:write('step\n') end end function Remdebug:step() dbg_command('step') end function Remdebug:step_over() dbg_command('over') end function Remdebug:continue() dbg_command('run') end function Remdebug:quit() dbg_command('exec os.exit(0)') end function Remdebug:inspect(word) dbg_command('eval', word) end function Remdebug:set_breakpoint(file, lno) local FileDir = props['FileDir']:gsub('\\', '/') if not find(FileDir, "/$")then FileDir = FileDir .. "/" end if self.local_dir and self.local_dir ~= "" and self.remote_dir and self.remote_dir ~= "" then local file_tmp = FileDir FileDir = gsub(file_tmp, self.local_dir, self.remote_dir) scite_debug('set_breakpoint(local to remote):'..file_tmp..file..'->'..FileDir..file..' ('..lno..')') end dbg_command('setb', FileDir..file..' '..lno) end function Remdebug:clear_breakpoint(file, line, num) if file then -- this function will only pass us the filename part, not the path! local FileDir = props['FileDir']:gsub('\\', '/') if not find(FileDir, "/$")then FileDir = FileDir .. "/" end if self.local_dir and self.local_dir ~= "" and self.remote_dir and self.remote_dir ~= "" then local file_tmp = FileDir FileDir = gsub(file_tmp, self.local_dir, self.remote_dir) scite_debug('clear_breakpoint(local to remote):'..file_tmp..file..'->'..FileDir..file..' ('..line..')') end dbg_command('delb', FileDir ..file..' '..line) else print('no breakpoint at '..file..':'..line) end end function Remdebug:backtrace(count) end function Remdebug:finish() end function Remdebug:locals() dbg_command('locals') end function Remdebug:detect_program_end(line) local _s,_e = find(line, 'finished') if _s then return find(line, '^Program finished') else return find(line, '^Program killed') end end register_debugger('remdebug', 'lua', Remdebug)