简体   繁体   English

如何正确调试 ncurses ?

[英]How to correctly debug ncurses ?

I wanna learn something from ncurses, so that I can use assembly to write some simple functions to draw graphics.我想从ncurses中学习一些东西,这样我就可以使用汇编编写一些简单的函数来绘制图形。

For example, when I step into initscr , then I'm right here /lib/x86_64-linux-gnu/libncurses.so.6 , I can't see any c code.例如,当我进入initscr时,我就在这里/lib/x86_64-linux-gnu/libncurses.so.6 ,我看不到任何 c 代码。 Do you have some any ways to solve this problem?你有什么方法可以解决这个问题吗?

I use below commands to install ncurses!我使用以下命令安装 ncurses!

wget https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.2.tar.gz

tar xvzf ncurses-6.2.tar.gz

cd ...

./configure --with-shared --with-normal --with-debug --enable-overwrite

make

sudo make install

你需要链接器libncurses_g.a

gcc -g ... -o ... /usr/lib/libncurses_g.a

./configure ...
make
sudo make install

99% of the time this installs to /usr/local . 99% 的时间都安装到/usr/local

/usr/local/include and /usr/local/lib are normally consulted before the usual /usr/include and /usr/lib when compiling and linking . /usr/local/include/usr/local/lib通常在编译和链接时通常在/usr/include/usr/lib之前进行咨询。 However /usr/local is completely ignored when loading shared libraries at run time.但是/usr/local在运行时加载共享库时会被完全忽略。 You need to do something special in order to accommodate this.你需要做一些特别的事情来适应这种情况。

There are several ways to do so.有几种方法可以做到这一点。

  1. Add -Wl,-rpath=/usr/local/lib to your link command.-Wl,-rpath=/usr/local/lib到您的链接命令。
  2. Set LD_LIBRARY_PATH environment variable to something that contains /usr/local/lib .将 LD_LIBRARY_PATH 环境变量设置为包含/usr/local/lib的内容。
  3. Add /usr/local/lib to your /etc/ld.so.conf (to be done with caution)./usr/local/lib添加到您的/etc/ld.so.conf中(谨慎操作)。

Note that basically all Linux terminal emulators support Unicode (using UTF-8) by default, as well as ANSI escape codes .请注意,基本上所有 Linux 终端仿真器都默认支持 Unicode(使用 UTF-8),以及ANSI 转义码

So, if you wanted to print a small red double-walled rectangle around the bright green letter "B" in the upper left corner, your program would simply write the following string (in C or assembly notation, ie the double quotes are not part of the string contents):因此,如果您想在左上角的亮绿色字母“B”周围打印一个小的红色双壁矩形,您的程序只需编写以下字符串(在 C 或汇编符号中,即双引号不是一部分字符串内容):

"\033[s\033[1;1H\033[0;31m╔═╗\033[0m\033[2;1H\033[0;31m║\033[1;32mB\033[0;31m║\033[0m\033[3;1H\033[0;31m╚═╝\033[0m\033[u"

where the two bytes ( 27,91 = \033[ ) comprise the control sequence introducer, CSI.其中两个字节( 27,91 = \033[ )组成控制序列引入器 CSI。

Do remember that write syscall is allowed to return a short count, especially when writing to a tty (terminal-like device).请记住, write系统调用允许返回一个短计数,尤其是在写入 tty(类似终端的设备)时。 If the return value is positive but smaller than the length of the string, you need to advance the pointer to the data by that amount, subtract the return value from the length, and do the syscall again, until it returns either the desired length or a value less than 1. (0 should not occur, and negative values are errno error codes.)如果返回值为正但小于字符串的长度,则需要将指向数据的指针前移该数量,从长度中减去返回值,然后再次执行系统调用,直到它返回所需的长度或小于 1 的值。(不应出现 0,负值是 errno 错误代码。)

What ncurses does, is support such codes in their various forms for basically all terminal-like devices, detects the correct one to be used via the TERM environment variable, and provides a lot of useful abstractions (via helper functions, like windows and such). ncurses 所做的是,基本上所有类似终端的设备都以各种形式支持此类代码,通过TERM环境变量检测要使用的正确代码,并提供许多有用的抽象(通过辅助函数,如 windows 等) . But the above, UTF-8 and ANSI escape codes, works in the majority of cases, and is a viable minimal implementation.但是上面的 UTF-8 和 ANSI 转义码在大多数情况下都有效,并且是可行的最小实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM