Ok, I just find that I may find the reason of this issue:
GDB will return a ">>>>>>cb_gdb:" (we call it FULL_GDB_PROMPT or GDB_PROMPT string, this is the customized gdb prompt by codeblocks) to indicate the previous command is executed correctly.
But it looks like every gdb command should return a GDB_PROMPT.
But when I have many custom script in the debugger setting dialog, such as: I put three command here.
source $(TARGET_COMPILER_DIR)bin\stl.gdb
source $(TARGET_COMPILER_DIR)bin\wx.gdb
set print elements 200
Those three command will return three GDB_PROMPT.
Also, the command like setting the directory command will also return a GDB_PROMPT.
After that, we are sending setting break point command, then wait to receive the bp index from gdb. This is a handshake, gdb will return the correct bp index.
Now, if we do not eat/clear the previous GDB_PROMPT, they will be buffered, and serves as the response string from gdb, so we get a bp index mismatch.
So, the solution should be simple:
We should clear/wait the GDB_PROMPT after the custom gdb command, this will not later confuse the normal breakpoint command handshake.