eclipse中的断点使用postgresql [英] breakpoints in eclipse using postgresql

查看:426
本文介绍了eclipse中的断点使用postgresql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用helios Eclipse来调试我的postgresql中的代码。



我的目的是要知道postgresql在连接查询期间如何使用连接算法,所以我开始调试 nodenestloop.c 在Executor文件夹中。



我在该文件中提供了断点,但是每当我尝试调试该文件时,控制转到main.c,永远不会回来,我如何将控件仅限于该特定文件(nodenestloop.c)



以下是我给出的以下字段在Helios Eclipse的Debug配置中。



C / C ++应用程序 - src / backend / postgres
项目 - pgsql



我按照以下链接中的步骤运行程序。



https://wiki.postgresql.org/wiki/Working_with_Eclipse#



我甚至没有审查字段从S开始点击=主要,但是当我这样做时,步骤和按钮不会被激活,并且出现了以下问题。



无法将主表保存到文件'/home/ravi/workspace/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources'。
/home/ravi/workspace/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources(Permission denied)



所以我使用sudo启动eclipse,但是这次eclipse的控制台中出现了以下错误。



root不允许执行PostgreSQL服务器。
服务器必须以非特权的用户标识启动,以防止
可能的系统安全损害。有关如何正确启动服务器的更多信息,请参阅
的文档。



任何人都可以帮助我。



谢谢

解决方案

问题1:用户ID不匹配



在线之间读取,好像您正在尝试调试以 postgres 用户身份运行的PostgreSQL实例,或其他用户ID无论如何因此,您尝试使用 sudo



这很痛苦,特别是在使用像Eclipse这样的IDE时。使用简单的 gdb ,您可以将 sudo gdb命令添加到所需的uid,例如 sudo -u postgres -p 12345 附加到以用户 postgres 运行的pid 12345。这将不适用于Eclipse。事实上,使用 sudo 运行它可能已经使您的工作空间有一些混乱的文件权限;运行:

  sudo chown -R ravi / home / ravi / workspace / 
/ pre>

修复文件所有权。



如果要使用Eclipse调试其他用户标识下的进程,你需要弄清楚如何使用sudo运行 gdb 。 do 不是只需运行所有的Eclipse与 sudo



问题2:尝试在Eclipse的控制下运行PostgreSQL



这样:


root执行的PostgreSQL服务器是不允许的。服务器必须以非特权的用户标识启动,以防止可能的系统安全隐患。有关如何正确启动服务器的更多信息,请参阅文档。


表明您也试图让Eclipse开始 postgres 直接。如果您尝试调试 postmaster ,那么这非常有用,但由于您正在讨论查询计划程序,因此您很想调试特定的后端。在Eclipse下启动postmaster是没用的,你会被附加到错误的进程。



我想你可能需要阅读有关PostgreSQL内部的文档: p>



正确执行



这是你需要的做 - 粗略的轮廓,因为我只使用Eclipse进行Java开发,并使用vim和gdb进行C开发:




  • 编译PostgreSQL(/ code> ./configure --enable-debug ,最好也是 CFLAGS = -ggdb -Og -f无省略帧指针)。在您的homedir中指定一个 - 前缀,如 - prefix = $ HOME / postgres-debug


  • 将您的调试版本的 bin 目录首先放在您的 PATH ,例如 export PATH = $ HOME / postgres-debug / bin:$ PATH


  • initdb -U postgres -D $ HOME / postgres-debug-data 调试版本中的一个新的PostgreSQL实例


  • 开始新的实例与 PGPORT = 5599 pg_ctl -D $ HOME / postgres-debug-data -l $ HOME / postgres-debug-data.log -w start


  • 连接 PGPORT = 5599 psql postgres


  • p>执行您需要做的任何设置


  • 使用获取后台进程ID SELECT pg_backend_pid() psql 会话中。让会议开放;这将是您调试的一个。


  • 将Eclipse的调试器附加到该进程ID,使用包含正在调试的PostgreSQL扩展源代码的Eclipse项目。确保Eclipse已配置,以便您可以找到您编译的PostgreSQL源代码(不知道该怎么做,请参阅手册)。


  • 设置任何所需的断点和恢复执行


  • psql 会话中,做任何你需要做的,扩展运行并点击断点


  • 当Eclipse中的断点执行暂停时,根据需要进行调试。




基本的误解?



另外,如果你真的所有这些工作:PostgreSQL是一个客户端/服务器应用程序。如果您正在尝试调试使用libpq或odbc的客户端程序,并希望在某些PostgreSQL后端扩展代码中触发断点,那将不会发生。客户端应用程序通过TCP / IP套接字与PostgreSQL进行通信。这是一个单独的程序。因为它们是单独的程序,所以在PostgreSQL服务器连接到客户端时,不能设置断点。如果要调试服务器,则必须将gdb连接到服务器。 PostgreSQL每个连接使用一个进程,因此您必须将gdb附加到正确的服务器进程。这就是为什么我说要使用上面的 SELECT pg_backend_pid(),并附加到进程ID。



上面链接的内部文档,和:




I am using helios Eclipse for debugging my code in postgresql.

My aim is to know how postgresql uses join algorithms during the join query, so I started to debug nodenestloop.c which is in the Executor folder.

I gave break points in that file, But whenever I try to debug that file, the control goes to main.c and never comes back,How do I constraint the control only to that particular file(nodenestloop.c)

Below are the following fields which I gave in Debug configurations of Helios Eclipse.

C/C++ Application - src/backend/postgres and project - pgsql

I followed the steps given in the following link for running the program.

https://wiki.postgresql.org/wiki/Working_with_Eclipse#

I even uncheked the field "Start on Start up=main" , but When I do that, The step in and Step over buttons are not activated and the following problem has popped up.

Could not save master table to file '/home/ravi/workspace/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources'. /home/ravi/workspace/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources (Permission denied)

So I started eclipse using sudo, but this time the following error has come in the console of eclipse.

"root" execution of the PostgreSQL server is not permitted. The server must be started under an unprivileged user ID to prevent possible system security compromise. See the documentation for more information on how to properly start the server.

Could any one help me with this.

Thank you

解决方案

Problem 1: User ID mismatch

Reading between the lines, it sounds like you're trying to debug a PostgreSQL instance that's running as the postgres user, or a different user ID to your own anyway. Hence your attempt to use sudo.

That's painful, especially when using an IDE like Eclipse. With plain gdb you can just sudo the gdb command to the desired uid, e.g. sudo -u postgres -p 12345 to attach to pid 12345 running as user postgres. This will not work with Eclipse. In fact, running it with sudo has probably left your workspace with some messed up file permissions; run:

sudo chown -R ravi /home/ravi/workspace/

to fix file ownership.

If you want to debug processes under other user IDs with Eclipse, you'll need to figure out how to make Eclipse run gdb with sudo. Do not just run all of Eclipse with sudo.

Problem 2: Trying to run PostgreSQL under the control of Eclipse

This:

"root" execution of the PostgreSQL server is not permitted. The server must be started under an unprivileged user ID to prevent possible system security compromise. See the documentation for more information on how to properly start the server.

suggests that you're also attempting to let Eclipse start postgres directly. That's very useful if you're trying to debug the postmaster, but since you're talking about the query planner it's clear you want to debug a particular backend. Launching the postmaster under Eclipse is useless for that, you'll be attached to the wrong process.

I think you probably need to read the documentation on PostgreSQL's internals:

Doing it right

Here's what you need to do - rough outline, since I've only used Eclipse for Java development and do my C development with vim and gdb:

  • Compile a debug build of PostgreSQL (compiled with ./configure --enable-debug and preferably also CFLAGS="-ggdb -Og -fno-omit-frame-pointer"). Specify a --prefix within your homedir, like --prefix=$HOME/postgres-debug

  • Put your debug build's bin directory first on your PATH, e.g. export PATH=$HOME/postgres-debug/bin:$PATH

  • initdb -U postgres -D $HOME/postgres-debug-data a new instance of PostgreSQL from your debug build

  • Start the new instance with PGPORT=5599 pg_ctl -D $HOME/postgres-debug-data -l $HOME/postgres-debug-data.log -w start

  • Connect with PGPORT=5599 psql postgres

  • Do whatever setup you need to do

  • Get the backend process ID with SELECT pg_backend_pid() in a psql session. Leave that session open; it's the one you'll be debugging.

  • Attach Eclipse's debugger to that process ID, using the Eclipse project that contains the PostgreSQL extension source code you're debugging. Make sure Eclipse is configured so it can find the PostgreSQL source code you compiled with too (no idea how to do that, see the manual).

  • Set any desired breakpoints and resume execution

  • In the psql session, do whatever you need to do to make your extension run and hit the breakpoint

  • When execution pauses at the breakpoint in Eclipse, debug as desired.

Basic misunderstandings?

Also, in case you're really confused about how all this works: PostgreSQL is a client/server application. If you are attempting to debug a client program that uses libpq or odbc, and expecting a breakpoint to trigger in some PostgreSQL backend extension code, that is not going to happen. The client application communicates with PostgreSQL over a TCP/IP socket. It's a separate program. gdb cannot set breakpoints in the PostgreSQL server when it's connected to the client, because they are separate programs. If you want to debug the server, you have to attach gdb to the server. PostgreSQL uses one process per connection, so you have to attach gdb to the correct server process. Which is why I said to use SELECT pg_backend_pid() above, and attach to the process ID.

See the internals documentation linked above, and:

这篇关于eclipse中的断点使用postgresql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆