diff --git a/modules/dap/session.py b/modules/dap/session.py index 67694bc..ad7868d 100644 --- a/modules/dap/session.py +++ b/modules/dap/session.py @@ -300,27 +300,30 @@ async def add_breakpoints(self) -> None: if self.capabilities.supportsDataBreakpoints: requests.append(self.set_data_breakpoints()) - if requests: - await core.wait(requests) + for request in requests: + core.run(request) async def set_exception_breakpoint_filters(self) -> None: if not self._transport: return - filters: list[str] = [] - filterOptions: list[dap.ExceptionFilterOptions] = [] - - for f in self.breakpoints.filters: - if f.enabled: - filters.append(f.dap.filter) - filterOptions.append(dap.ExceptionFilterOptions( - f.dap.filter, - f.condition, - )) - - await self.request('setExceptionBreakpoints', { - 'filters': filters, - 'filterOptions': filterOptions - }) + try: + filters: list[str] = [] + filterOptions: list[dap.ExceptionFilterOptions] = [] + + for f in self.breakpoints.filters: + if f.enabled: + filters.append(f.dap.filter) + filterOptions.append(dap.ExceptionFilterOptions( + f.dap.filter, + f.condition, + )) + + await self.request('setExceptionBreakpoints', { + 'filters': filters, + 'filterOptions': filterOptions + }) + except core.Error as e: + self.log.error('Error while exception filters: {}'.format(e)) async def set_function_breakpoints(self) -> None: if not self._transport: @@ -333,17 +336,21 @@ async def set_function_breakpoints(self) -> None: self.log.error('This debugger does not support function breakpoints') return - dap_breakpoints = list(map(lambda b: b.dap, breakpoints)) + try: + dap_breakpoints = list(map(lambda b: b.dap, breakpoints)) - response = await self.request('setFunctionBreakpoints', { - 'breakpoints': dap_breakpoints - }) - results: list[dap.Breakpoint] = response['breakpoints'] + response = await self.request('setFunctionBreakpoints', { + 'breakpoints': dap_breakpoints + }) + results: list[dap.Breakpoint] = response['breakpoints'] - for result, b in zip(results, breakpoints): - self.breakpoints.function.set_breakpoint_result(b, self, result) - if result.id is not None: - self.breakpoints_for_id[result.id] = b + for result, b in zip(results, breakpoints): + self.breakpoints.function.set_breakpoint_result(b, self, result) + if result.id is not None: + self.breakpoints_for_id[result.id] = b + + except core.Error as e: + self.log.error('Error while adding function breakpoints: {}'.format(e)) async def set_data_breakpoints(self) -> None: if not self._transport: @@ -351,14 +358,18 @@ async def set_data_breakpoints(self) -> None: breakpoints = list(filter(lambda b: b.enabled, self.breakpoints.data)) dap_breakpoints = list(map(lambda b: b.dap, breakpoints)) - response = await self.request('setDataBreakpoints', { - 'breakpoints': dap_breakpoints - }) - results: list[dap.Breakpoint] = response['breakpoints'] - for result, b in zip(results, breakpoints): - self.breakpoints.data.set_breakpoint_result(b, self, result) - if result.id is not None: - self.breakpoints_for_id[result.id] = b + try: + response = await self.request('setDataBreakpoints', { + 'breakpoints': dap_breakpoints + }) + results: list[dap.Breakpoint] = response['breakpoints'] + for result, b in zip(results, breakpoints): + self.breakpoints.data.set_breakpoint_result(b, self, result) + if result.id is not None: + self.breakpoints_for_id[result.id] = b + + except core.Error as e: + self.log.error('Error while adding data breakpoints: {}'.format(e)) async def set_breakpoints_for_file(self, file: str, breakpoints: list[SourceBreakpoint]) -> None: if not self._transport: @@ -401,6 +412,7 @@ async def set_breakpoints_for_file(self, file: str, breakpoints: list[SourceBrea self.breakpoints_for_id[result.id] = b except Error as e: + self.log.error('Error while adding breakpoints: {}'.format(e)) for b in enabled_breakpoints: self.breakpoints.source.set_breakpoint_result(b, self, dap.Breakpoint(verified=False, message=str(e))) @@ -445,7 +457,6 @@ async def stop(self): except Error as e: core.exception() - # we couldn't terminate either not a launch request or the terminate request failed # so we foreceully disconnect await self.request('disconnect', { @@ -688,19 +699,20 @@ def on_loaded_source_event(self, event: dap.LoadedSourceEvent): # it depends on when the debug adapter chooses it is ready for configuration information # when it does happen we can then add all the breakpoints and complete the configuration # NOTE: some adapters appear to send the initialized event multiple times - @core.schedule - async def on_initialized_event(self): - try: - await self.add_breakpoints() - except core.Error as e: - self.log.error('there was an error adding breakpoints {}'.format(e)) - + def on_initialized_event(self): + self.add_breakpoints() + if self.capabilities.supportsConfigurationDoneRequest: - try: + self.configuration_done() + + def configuration_done(self): + async def run(): + try: await self.request('configurationDone', {}) except core.Error as e: self.log.error('there was an error in configuration done {}'.format(e)) - + core.run(run()) + def on_output_event(self, event: dap.OutputEvent): self.listener.on_session_output_event(self, event)