Double renaming

Quite often I have to revise old code in IDA Pro. Given its age, it happens almost every time a new feature is added (two exceptions: the bTree and the virtual memory manager are basically the same as about 17 years ago).

One usual approach to is to use grep to find all references to the function or variable of interest and verify the code surrounding each occurrence. While this approach gives very good results, I prefer to not use it. If for some reason I get distracted and forget to revise a couple of locations, a new bug might be added to previously correct code.
There is another technique I use for such code revisions. I temporarily rename the revised object to a new name. For example, I add an underscore to it.
After that I launch make and get a long list of error messages from the compiler. Each location must be revised and corrected before the application can be built. Even if I get interrupted and have to continue tomorrow (or take my vacations), no single occurrence will be missed.
The tedious part of the method is the second renaming: now I revert to the original name and remove the underscores from the code. Sometimes I automate it with the editor’s search/replace command but, however, it is better to be prudent and not to surrender to the temptation of replacing everything at once.
This technique is excellent for global code revisions. There are some limitations, though: it won’t work for virtual or overloaded functions. Maybe this is the reason why you will find so few of them in IDA 🙂

7 thoughts on “Double renaming”

  1. This is why I love working with modern Java IDEs: You can search for references to your classes/methods project-wide, and get a complete list, with no omissions or extras. Do C++ IDEs not provide features like this? (Never used one..)

  2. One reason I love the “Refactor” features of Visual Studio, alas, I don’t think they are available for C/C++ projects.

  3. Nicholas, some C++ IDEs do have that feature, but that’s no different than the grep method Ilfak mentioned. It has the same problem: if you’re not paying attention, you can skip one on the list. Much better to do the rename thing.

  4. Maybe a stupid idea, but I’ll give it a shot:
    Usually the project is already compiled. If you compiled in debug mode without any inlining or optimizations, a smart tool should be able to read the export table of the object files and therefore know where the variable/function is used. Then, by reading the symbols to know the locations, the tool should be able to automagically rename the calls/uses.
    It is probably less errorprone than a grep and easier to adapt to multiple languages. You are somehow using the compiler as a code parser, and instead of hacking around the compiler’s code, you just read its output: the object files.
    But I’m probably missing something which makes this idea impossible… But I thought it could be interesting to share it, insofar as you probably already have pretty much all the coded needed to try this tool idea 🙂
    PS: if it works, a freeware would be welcomed 😉

  5. “grep” is old school, good to see people still know even what it is 😛
    Ahh, the good old days of using grep and QEdit for everying..
    “Multi-Edit” ( has a global rename feature in it.
    I used load all of my project files into MultiEdit temporarily just to rename them.

  6. SlickEdit has some basic C++ refactorins, rename is one of them.
    Visual Assist X has actual good C++ refactorings and is a plugin for VS2005.
    Refactor! has some beta C++ refactoring support. It is a plugin for VS2005.
    Ref++ is a C++ refactoring plugin for VS2005
    Xrefactory is a C++ refactoring plugin for emacs.
    I use visual assist x and find it quite helpful. It’s not nearly as powerful as say ReSharper or most Java refactoring utilties though however C++ is infinitely harder to parse correctly than either C# or Java.

  7. Ilfak, that is a technique I have been using too. However, to ease up the second renaming, I usually change the original name by adding to it a unique, unintelligible prefix, say “axxa_bxxb_cxxc_dxxd_”. After each location has been modified, I can use the “replace all” function of the IDE, as the prefix is for sure not used elsewhere in the code.

Comments are closed.