I'm trying to construct a recursively enumerable TM for this language. (Useless state: one that is never entered during a computation on any input).
The TM L: Write out all of M's states, generate input in lexicographical order one at a time, and after one is generated, simulate M on the input and mark down which states M has entered. If M enters all states, halt, if M halts without entering all states, generate the next input in lexicographical order and repeat the process. (Keeping the list of entered states between simulations, since once a state is entered for any input, it is not considered useless).
My question is, what happens if M does not halt on input $w_i$ but will halt and in fact enter all states on $w_{i+1}$? Then L will get stuck in an infinite loop on $w_i$ and not realize that M's behavior on $w_{i+1}$ means L should actually accept--thus L will not eventually halt and accept.
Is there a way to deal with this problem or is this TM just not the right way to show this language is recursively enumerable?