def __init__(self, executable): self.executable = executable self.name = "addr2line -e " + os.path.basename(self.executable) Console.__init__(self, self.name, on_input=Addr2line.on_input) self.create_link(file_line_re, self.onclick) self.clear() self.write("Backtrace ?") self.enable_input(True) MDI.get(self.name).raise_window()
def onclick(self, text): matched = re.match(file_line_re, text) buffer = EditorBuffer.get(File(matched.group(2))) MDI.get_by_child(buffer.current_view()).raise_window() line = int(matched.group(3)) column = matched.group(5) if column is not None: buffer.current_view().goto(buffer.at(line, int(column))) else: buffer.current_view().goto(buffer.at(line, 1))
def on_exit(self, status, remaining_output): shutil.rmtree(tmp_dir) if status != 0: GPS.Console("Messages").write("error: failed to display standard.ads", mode="error") buffer = EditorBuffer.get_new() buffer.delete() # delete any text inserted via templates buffer.insert(buffer.at(1, 1), remaining_output) buffer.set_lang('ada') buffer.current_view().set_read_only(True) MDI.get_by_child(buffer.current_view()).rename('package Standard')
def show_unused_entities(where, globals_only): """List all unused global entities from WHERE in the locations window""" Editor.register_highlighting("Unused_Entities", "blue") Locations.remove_category("Unused entity") MDI.get("Messages").raise_window() for e in UnusedIterator(where, globals_only=globals_only): Locations.add(category="Unused entity", file=e.declaration().file(), line=e.declaration().line(), column=e.declaration().column(), message="unused entity " + e.name(), highlight="Unused_Entities", length=len(e.name())) Console().write("Done searching for unused entities\n")
def update_project_view_title(t): new_name = Project.root().file().name() new_short_name = Project.root().name() view = MDI.get("Project View") if view is not None: view.rename(new_name, new_short_name) t.remove()
def save_excursion(f, args, kwargs, undo_group=True): """ Save current buffer, cursor position and selection and execute f. (args and kwargs) are passed as arguments to f. They indicate that any number of parameters (named or unamed) can be passed in the usual way to save_excursion, and they will be transparently passed on to f. If undo_group is True, then all actions performed by f will be grouped so that the user needs perform only one single undo to restore previous start. Then restore the context as it was before, even in the case of abnormal exit. Example of use:: def my_subprogram(): def do_work(): pass # do actual work here save_excursion(do_work) See also the with_save_excursion decorator below for cases when you need to apply save_excursion to a whole function. """ mdi = MDI.current() buffer = EditorBuffer.get() view = buffer.current_view() cursor = view.cursor() start = buffer.selection_start().create_mark() end = buffer.selection_end().create_mark(left_gravity=False) had_selection = start.location() != end.location() try: if undo_group: with buffer.new_undo_group(): return f(*args, **kwargs) else: return f(*args, **kwargs) finally: try: # View might have been destroyed mdi.raise_window() view.goto(cursor) except Exception: # In this case use the next view available if any view = buffer.current_view() if not view: return if had_selection: buffer.select(start.location(), end.location()) else: buffer.current_view().goto(start.location()) start.delete() end.delete()
def remove_gcov(): "Cleanup the gcov coverage files" if not MDI.yes_no_dialog( "This will remove all .gcov and .gcda files, are you sure ?"): return # Look in all the projects for p in Project.root().dependencies(True): object_dirs = p.object_dirs(False) if len(object_dirs) > 0: object_dir = object_dirs[0] # Browse in the object dirs for f in os.listdir(object_dir): # if f is a .gcda or a .gcov, remove it if f.find(".gcda") != -1 or f.find(".gcov") != -1: os.remove(object_dir + os.sep + f)
def open_addr2line_console(): executable = MDI.input_dialog("Location of the executable ?", "Exec")[0] Addr2line(executable)
def on_exit(self, process, status, full_output): MDI.get(self.name).raise_window() self.write("\n\nBacktrace ?") self.enable_input(True)
def run_gcov(): "Run gcov to generate the coverage files" # Verify that the version of gcov is recent enough to support response # files and reading of .gc?? data in multiple directories. try: p = Process("gcov --version") out = p.get_result() p = re.compile("[1-9][0-9][0-9][0-9][0-1][0-9][0-3][0-9]") found = p.findall(out) if not found: MDI.dialog("Could not find a date in the output of gcov.") else: date = found[0] if int(date) < 20071005: MDI.dialog("Your version of gcov is dated " + str(date) + ".\nThis plugin requires gcov for GNAT dated " + "20071005 or later.") return except Exception: MDI.dialog("""Could not read gcov version number. Make sure you are using gcov for GNAT dated 20071005 or later.""") # Determine the root project root_project = Project.root() # Determine where to create the gcov info GCOV_ROOT = os.getenv("GCOV_ROOT") if not GCOV_ROOT: root_object_dirs = root_project.object_dirs(False) if not root_object_dirs: MDI.dialog("""The root project does not have an object directory. Please add one, or set the enviroment variable GCOV_ROOT to the directory where you would like the gcov files to be generated.""") return else: gcov_dir = root_object_dirs[0] else: gcov_dir = GCOV_ROOT if not os.access(gcov_dir, os.R_OK and os.W_OK): MDI.dialog(""" Could not access the directory: """ + gcov_dir + """ Please point the environment variable GCOV_ROOT to a directory on which you have permission to read and write. """) input_file = os.path.abspath(os.path.join(gcov_dir, "gcov_input.txt")) # List all the projects projects = root_project.dependencies(True) # List all object dirs object_dirs = root_project.object_dirs(True) # Write the response file res = open(input_file, 'w') gcda_file_found = False gcno_file_found = False for p in projects: sources = p.sources(False) for s in sources: n = s.path basename = n[max(n.rfind('\\'), n.rfind('/')) + 1:len(n)] unit = basename[0:basename.rfind('.')] for object_dir in object_dirs: gcda = object_dir + os.sep + unit + ".gcda" # If we have not yet found at least one .gcno file, attempt to # find one. This is to improve the precision of error messages, # and detect the case where compilation was successful but the # executable has never been run. if not gcno_file_found: gcno = object_dir + os.sep + unit + ".gcno" if os.access(gcno, os.F_OK): gcno_file_found = True if os.access(gcda, os.F_OK): gcda_file_found = True # Write one entry in response file # Escape all backslashes. gcda = gcda.replace('\\', '\\\\') res.write('"' + gcda + '"' + "\n") break res.close() open(input_file).read() if not gcno_file_found: # No gcno file was found: display an appropriate message. MDI.dialog( """ No ".gcno" file was found in any of the object directories. Make sure you have compiled the sources of interest with the "Code coverage" flags.""") else: if not gcda_file_found: # Some gcno files were found, but no gcna files. MDI.dialog( """ No ".gcda" file was found in any of the object directories. Make sure you have run the executable(s) at least once. """) else: # Run gcov Gcov_Process("gcov", "@%s" % input_file, directory=gcov_dir)