您的位置:首页 > 产品设计 > UI/UE

解决gdb调试时tui源码窗口由于显示dos格式文件导致的行号混乱问题

2019-01-19 15:21 2759 查看

由于调试环境原因无法使用高版本GDB,而低版本GDB在代码为dos格式时,在tui源码窗口内每行代码都会多出一行空行导致行号混乱,例如

[code]#include "defs.h"
#include "main.h"
#include "gdb_string.h"
#include "interps.h"

int
main (int argc, char **argv)
{
struct captured_main_args args;
memset (&args, 0, sizeof args);
args.argc = argc;
args.argv = argv;
args.use_windows = 0;
args.interpreter_p = INTERP_CONSOLE;
return gdb_main (&args);
}

显示为:

 解决方法如下:

一、利用dos2unix命令修改源文件格式

[code]dos2unix -k 文件名 // -k参数保持源文件日期不变

二、

修改gdb源码目录/gdb/tui/tui-source.c文件中tui_set_source_content()函数中的换行符处理部分,然后重新编译

http://ftp.gnu.org/gnu/gdb/

gdb-6.3对应代码为:

         if (c != EOF)
          {
            i = strlen (src_line) - 1;
            do
              {
                if ((c != '\n') &&
                   /*屏蔽 (c != '\r')  &&*/ (++i < threshold))
                  {
                    // 新增修改,将回车符0x0d改为空格,防止显示为空行
                    if ( c=='\r' ) 
                      c = ' ';

                    if (c < 040 && c != '\t')
                      {
                        src_line[i++] = '^';
                        src_line[i] = c + 0100;
                      }
                    else if (c == 0177)
                      {
                        src_line[i++] = '^';
                        src_line[i] = '?';
                      }
                    else
                      {   /* Store the charcter in the line
                             buffer.  If it is a tab, then
                             translate to the correct number of
                             chars so we don't overwrite our
                             buffer.  */
                        if (c == '\t')
                          {
                            int j, max_tab_len = tui_default_tab_len ();

                            for (j = i - (
                                 (i / max_tab_len) * max_tab_len);
                                 ((j < max_tab_len) &&
                                  i < threshold);
                                 i++, j++)
                              src_line[i] = ' ';
                            i--;
                          }
                        else
                          src_line[i] = c;
                      }
                    src_line[i + 1] = 0;
                  }
                else
                  {       /* If we have not reached EOL, then eat
                             chars until we do  */
                    while (c != EOF && c != '\n' /*屏蔽&& c != '\r'*/)
                      c = fgetc (stream);
                  }
              }
            while (c != EOF && c != '\n' && /*屏蔽c != '\r' &&*/
                   i < threshold && (c = fgetc (stream)));
          }
 

三、编译优化导致的混乱可用-O0选项重新编译

[code]gcc -g -O0 -o XXX XXX.c

 貌似-O2就没问题了

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐